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 committed Apr 17, 2023
1 parent 7adea6f commit 14628d7
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 20 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/external-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ jobs:
- name: 'Set up Java'
uses: actions/setup-java@v3
with:
java-version: 17
java-version: |
11
17
# Adapt the toolchains.xml generated by this action
mvn-toolchain-id: |
JavaSE-11
JavaSE-17
distribution: 'temurin'
if: ${{ env.BASE_REPO != env.PR_HEAD_REPO }}

Expand All @@ -43,6 +49,6 @@ jobs:
- name: Build and test
uses: coactions/setup-xvfb@v1
with:
run: mvn clean verify --show-version -PuseJenkinsSnapshots -Dsurefire.rerunFailingTestsCount=3
run: mvn clean verify --show-version -PuseJenkinsSnapshots,strict-jdk -Dsurefire.rerunFailingTestsCount=3
working-directory: org.eclipse.xtext.full.releng
if: ${{ env.BASE_REPO != env.PR_HEAD_REPO }}
22 changes: 17 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ jobs:
- name: 'Set up Java'
uses: actions/setup-java@v3
with:
java-version: 17
java-version: |
11
17
# Adapt the toolchains.xml generated by this action
mvn-toolchain-id: |
JavaSE-11
JavaSE-17
distribution: 'temurin'

- name: 'Cache Maven packages'
Expand All @@ -32,8 +38,8 @@ jobs:

- name: Build and test
uses: coactions/setup-xvfb@v1
with:
run: mvn clean verify --show-version -PuseJenkinsSnapshots -Dsurefire.rerunFailingTestsCount=3
with:
run: mvn clean verify --show-version -PuseJenkinsSnapshots,strict-jdk -Dsurefire.rerunFailingTestsCount=3
working-directory: org.eclipse.xtext.full.releng

build-maven-artifacts:
Expand All @@ -46,7 +52,13 @@ jobs:
- name: 'Set up Java'
uses: actions/setup-java@v3
with:
java-version: 17
java-version: |
11
17
# Adapt the toolchains.xml generated by this action
mvn-toolchain-id: |
JavaSE-11
JavaSE-17
distribution: 'temurin'

- name: 'Cache Maven packages'
Expand All @@ -57,5 +69,5 @@ jobs:
restore-keys: ${{ runner.os }}-maven

- name: Build Maven artifacts
run: mvn clean verify --show-version -PuseJenkinsSnapshots
run: mvn clean verify --show-version -PuseJenkinsSnapshots,strict-jdk
working-directory: org.eclipse.xtext.maven.releng
35 changes: 26 additions & 9 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()}"
//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
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
64 changes: 61 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
</scm>

<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
<tycho-version>2.7.5</tycho-version>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
<tycho-version>3.0.4</tycho-version>

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down Expand Up @@ -187,6 +187,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 @@ -401,6 +406,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 Expand Up @@ -583,7 +641,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<!-- MJAVADOC-620 – Maven Javadoc Plugin fails to resolve the dependencies
<!-- MJAVADOC-620 – Maven Javadoc Plugin fails to resolve the dependencies
when used with Java 11 -->
<version>3.5.0</version>
<configuration>
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 14628d7

Please sign in to comment.