Improve detection of JDK on Windows (#10294)
This commit is contained in:
parent
7db16f174d
commit
fa73edb9bf
|
|
@ -23,7 +23,6 @@ jobs:
|
||||||
jobName: Code_check
|
jobName: Code_check
|
||||||
jobDisplayName: Code check
|
jobDisplayName: Code check
|
||||||
agentOs: Windows
|
agentOs: Windows
|
||||||
installJdk: false
|
|
||||||
steps:
|
steps:
|
||||||
- powershell: ./eng/scripts/CodeCheck.ps1 -ci
|
- powershell: ./eng/scripts/CodeCheck.ps1 -ci
|
||||||
displayName: Run eng/scripts/CodeCheck.ps1
|
displayName: Run eng/scripts/CodeCheck.ps1
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ jobs:
|
||||||
BuildDirectory: ${{ parameters.buildDirectory }}
|
BuildDirectory: ${{ parameters.buildDirectory }}
|
||||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||||
TeamName: AspNetCore
|
TeamName: AspNetCore
|
||||||
${{ if eq(parameters.agentOs, 'Windows') }}:
|
${{ if and(eq(parameters.installJdk, 'true'), eq(parameters.agentOs, 'Windows')) }}:
|
||||||
JAVA_HOME: $(Agent.BuildDirectory)\.tools\jdk
|
JAVA_HOME: $(Agent.BuildDirectory)\.tools\jdk
|
||||||
${{ if or(ne(parameters.codeSign, true), ne(variables['System.TeamProject'], 'internal')) }}:
|
${{ if or(ne(parameters.codeSign, true), ne(variables['System.TeamProject'], 'internal')) }}:
|
||||||
_SignType: ''
|
_SignType: ''
|
||||||
|
|
|
||||||
38
build.ps1
38
build.ps1
|
|
@ -303,6 +303,44 @@ $MSBuildArguments += "/p:_RunSign=$Sign"
|
||||||
$MSBuildArguments += "/p:TargetArchitecture=$Architecture"
|
$MSBuildArguments += "/p:TargetArchitecture=$Architecture"
|
||||||
$MSBuildArguments += "/p:TargetOsName=win"
|
$MSBuildArguments += "/p:TargetOsName=win"
|
||||||
|
|
||||||
|
if (($All -or $BuildJava) -and -not $NoBuildJava) {
|
||||||
|
$foundJdk = $false
|
||||||
|
$javac = Get-Command javac -ErrorAction Ignore -CommandType Application
|
||||||
|
if ($env:JAVA_HOME) {
|
||||||
|
if (-not (Test-Path "${env:JAVA_HOME}\bin\javac.exe")) {
|
||||||
|
Write-Error "The environment variable JAVA_HOME was set, but ${env:JAVA_HOME}\bin\javac.exe does not exist. Remove JAVA_HOME or update it to the correct location for the JDK. See https://www.bing.com/search?q=java_home for details."
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host -f Magenta "Detected JDK in ${env:JAVA_HOME} (via JAVA_HOME)"
|
||||||
|
$foundJdk = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($javac) {
|
||||||
|
$foundJdk = $true
|
||||||
|
$javaHome = Split-Path -Parent (Split-Path -Parent $javac.Path)
|
||||||
|
$env:JAVA_HOME = $javaHome
|
||||||
|
Write-Host -f Magenta "Detected JDK in $javaHome (via PATH)"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
$jdkVersion = (Get-Item HKLM:\SOFTWARE\JavaSoft\JDK | Get-ItemProperty -name CurrentVersion).CurrentVersion
|
||||||
|
$javaHome = (Get-Item HKLM:\SOFTWARE\JavaSoft\JDK\$jdkVersion | Get-ItemProperty -Name JavaHome).JavaHome
|
||||||
|
if (Test-Path "${env:JAVA_HOME}\bin\java.exe") {
|
||||||
|
$env:JAVA_HOME = $javaHome
|
||||||
|
Write-Host -f Magenta "Detected JDK $jdkVersion in $env:JAVA_HOME (via registry)"
|
||||||
|
$foundJdk = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Verbose "Failed to detect Java: $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $foundJdk) {
|
||||||
|
Write-Error "Could not find the JDK. See $PSScriptRoot\docs\BuildFromSource.md for details on this requirement."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
|
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ Building ASP.NET Core on Windows requires:
|
||||||
```
|
```
|
||||||
* Git. <https://git-scm.org>
|
* Git. <https://git-scm.org>
|
||||||
* NodeJS. LTS version of 10.14.2 or newer <https://nodejs.org>
|
* NodeJS. LTS version of 10.14.2 or newer <https://nodejs.org>
|
||||||
* Java Development Kit (JDK) v8 with Java Runtime Environment (JRE) v8. See https://www.oracle.com/technetwork/java/javase/downloads/index.html
|
* Java Development Kit 11 or newer. Either:
|
||||||
|
* OpenJDK <https://jdk.java.net/>
|
||||||
|
* Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
|
||||||
|
|
||||||
### macOS/Linux
|
### macOS/Linux
|
||||||
|
|
||||||
|
|
@ -31,8 +33,8 @@ Building ASP.NET Core on macOS or Linux requires:
|
||||||
* At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
|
* At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
|
||||||
* Git <https://git-scm.org>
|
* Git <https://git-scm.org>
|
||||||
* NodeJS. LTS version of 10.14.2 or newer <https://nodejs.org>
|
* NodeJS. LTS version of 10.14.2 or newer <https://nodejs.org>
|
||||||
* Java Development Kit 10 or newer. Either:
|
* Java Development Kit 11 or newer. Either:
|
||||||
* OpenJDK <http://jdk.java.net/10/>
|
* OpenJDK <https://jdk.java.net/>
|
||||||
* Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
|
* Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
|
||||||
|
|
||||||
## Clone the source code
|
## Clone the source code
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue