Skip to content

Commit

Permalink
Build with Tycho 3.0.4 and set up Maven toolchains
Browse files Browse the repository at this point in the history
General guide for Maven toolchains:
https://maven.apache.org/guides/mini/guide-using-toolchains.html
Using the Maven-Toolchain-Plugin and its 'toolchain' goal the
maven-compiler-plugin is configured to use a JDK from the toolchain that
matches the specified release version.

Configure the Tycho-Compiler-Plugin to use the JDK in the toolchain that
matches the Bundle-RequiredExecutionEnvironment:
https://tycho.eclipseprojects.io/doc/3.0.4/tycho-compiler-plugin/compile-mojo.html#useJDK

Configure the Maven-Surefire-Plugin to use a specific JDK version from
the toolchain to launch a test runtime:
https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#jdkToolchain

Configure the Tycho-Surefire-Plugin to use a specific JDK version from
the toolchain to launch a test runtime:
https://tycho.eclipseprojects.io/doc/3.0.4/tycho-surefire-plugin/test-mojo.html#useJDK

About the toolchains.xml generated by the setup-java Github action and
the exported JAVA_HOME_ environment variables:
- https://github.com/actions/setup-java/#install-multiple-jdks
- https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Modifying-Maven-Toolchains

Fixes #2216
  • Loading branch information
HannesWell authored and LorenzoBettini committed Apr 19, 2023
1 parent 579935e commit a8ecc4f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 27 deletions.
52 changes: 26 additions & 26 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ pipeline {

parameters {
choice(name: 'TARGET_PLATFORM', choices: ['r202203', 'r202206', 'r202209', 'r202212', 'r202303', 'latest'], description: 'Which Target Platform should be used?')
// see https://wiki.eclipse.org/Jenkins#JDK
choice(name: 'JDK_VERSION', description: 'Which JDK should be used?', choices: [
'temurin-jdk11-latest', 'temurin-jdk17-latest'
])
choice(name: 'JDK_VERSION', choices: [ '11', '17' ], description: 'Which JDK version should be used?')
}

triggers {
parameterizedCron(env.BRANCH_NAME == 'main' ? '''
H H(0-1) * * * %TARGET_PLATFORM=r202203;JDK_VERSION=temurin-jdk17-latest
H H(3-4) * * * %TARGET_PLATFORM=latest;JDK_VERSION=temurin-jdk17-latest
H H(0-1) * * * %TARGET_PLATFORM=r202203;JDK_VERSION=17
H H(3-4) * * * %TARGET_PLATFORM=latest;JDK_VERSION=17
''' : '')
}

Expand All @@ -28,7 +25,8 @@ pipeline {

tools {
maven "apache-maven-3.8.6"
jdk "${params.JDK_VERSION}"
// see https://wiki.eclipse.org/Jenkins#JDK
jdk "temurin-jdk17-latest"
}

stages {
Expand Down Expand Up @@ -59,10 +57,29 @@ pipeline {
stage('Maven/Tycho Build & Test') {
environment {
MAVEN_OPTS = "-Xmx1500m"
JAVA_HOME_11_X64 = tool(type:'jdk', name:'temurin-jdk11-latest')
JAVA_HOME_17_X64 = tool(type:'jdk', name:'temurin-jdk17-latest')
}
steps {
xvnc(useXauthority: true) {
sh "./full-build.sh --tp=${selectedTargetPlatform()} ${javaVersionBasedProperties()}"
//TODO: remove the following test print out
sh '''
echo 'JAVA_HOME_11_X64=${JAVA_HOME_11_X64}'
echo 'JAVA_HOME_17_X64=${JAVA_HOME_17_X64}'
echo 'Predefined Jenkins Toolchain content'
cat ~/.m2e/toolchains.xml
'''
script {
def mavenSurfireJDKToolchain = params.JDK_VERSION
def tychoSurefireJDK = params.JDK_VERSION == '17' ? 'SYSTEM' : 'BREE'
sh """
./full-build.sh --tp=${selectedTargetPlatform()} \
-Pstrict-jdk
--toolchains releng/toolchains.xml
-Dmaven.surefire.runtimeJDK=${mavenSurfireJDKToolchain} \
-Dtycho.surefire.runtimeJDK=${tychoSurefireJDK}
"""
}
}
}// END steps
} // END stage
Expand Down Expand Up @@ -116,7 +133,7 @@ pipeline {

/** return the Java version as Integer (8, 11, ...) */
def javaVersion() {
return Integer.parseInt(params.JDK_VERSION.replaceAll(".*-jdk(\\d+).*", "\$1"))
return Integer.parseInt(params.JDK_VERSION)
}

/** returns true when this build was triggered by an upstream build */
Expand Down Expand Up @@ -161,20 +178,3 @@ def selectedTargetPlatform() {
return tp
}
}

/**
* Tycho 3 requires Java 17.
* If the build uses Java version 11, we return the proper tycho-version override.
* Otherwise, we return an empty string.
*/
def javaVersionBasedProperties() {
def javaVersion = javaVersion()

if (javaVersion<17) {
println("Switching to Tycho 2.7.5 with Java ${javaVersion}")
return '-Dtycho-version=2.7.5'
} else {
return ''
}
}

6 changes: 5 additions & 1 deletion jenkins/nightly-deploy/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ pipeline {
}
}
stage('Maven Tycho Build, Sign, Deploy') {
environment {
JAVA_HOME_11_X64 = tool(type:'jdk', name:'temurin-jdk11-latest')
JAVA_HOME_17_X64 = tool(type:'jdk', name:'temurin-jdk17-latest')
}
steps {
withCredentials([file(credentialsId: 'secret-subkeys.asc', variable: 'KEYRING')]) {
sh 'gpg --batch --import "${KEYRING}"'
sh 'for fpr in $(gpg --list-keys --with-colons | awk -F: \'/fpr:/ {print $10}\' | sort -u); do echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key ${fpr} trust; done'
}
sshagent(['projects-storage.eclipse.org-bot-ssh']) {
sh './full-deploy.sh -Peclipse-sign,sonatype-oss-release,release-snapshot'
sh ' ./full-deploy.sh -Peclipse-sign,sonatype-oss-release,release-snapshot,strict-jdk --toolchains releng/toolchains.xml'
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
<current-release-zip-directory>${releases-zip-directory}/${current-release-zip-subdirectory}</current-release-zip-directory>

<site.label>TMF Xtext Update Site</site.label>

<!-- By default use running java version in test runtimes-->
<maven.surefire.runtimeJDK>${java.specification.version}</maven.surefire.runtimeJDK>
<tycho.surefire.runtimeJDK>SYSTEM</tycho.surefire.runtimeJDK>

</properties>

<dependencyManagement>
Expand Down Expand Up @@ -400,6 +405,59 @@
</plugins>
</build>
</profile>
<profile>
<id>strict-jdk</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>${maven.compiler.release}</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<configuration>
<useJDK>BREE</useJDK>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<useJDK>${tycho.surefire.runtimeJDK}</useJDK>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jdkToolchain>
<version>${maven.surefire.runtimeJDK}</version>
</jdkToolchain>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

<build>
Expand Down
25 changes: 25 additions & 0 deletions releng/toolchains.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF8"?>
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<toolchain>
<type>jdk</type>
<provides>
<id>JavaSE-11</id>
<version>11</version>
</provides>
<configuration>
<jdkHome>${env.JAVA_HOME_11_X64}</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<id>JavaSE-17</id>
<version>17</version>
</provides>
<configuration>
<jdkHome>${env.JAVA_HOME_17_X64}</jdkHome>
</configuration>
</toolchain>
</toolchains>

0 comments on commit a8ecc4f

Please sign in to comment.