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 eclipse-xtext#2216

Co-authored-by: Lorenzo Bettini <[email protected]>
  • Loading branch information
HannesWell and LorenzoBettini committed Apr 19, 2023
1 parent 579935e commit 6381d98
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
26 changes: 7 additions & 19 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pipeline {

tools {
maven "apache-maven-3.8.6"
jdk "${params.JDK_VERSION}"
jdk "temurin-jdk17-latest"
}

stages {
Expand Down Expand Up @@ -59,10 +59,15 @@ 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()}"
sh """
./full-build.sh --tp=${selectedTargetPlatform()} \
${javaVersion() == 17 ? '' : '--toolchains releng/toolchains.xml -Pstrict-release-jdk'}
"""
}
}// END steps
} // END stage
Expand Down Expand Up @@ -161,20 +166,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 ''
}
}

27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,33 @@
</plugins>
</build>
</profile>
<profile>
<id>strict-release-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>
<!-- Toolchain selected by maven/tycho-compiler for compilation and maven/tycho-surefire as JRE of launched test-runtimes-->
<version>${maven.compiler.release</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</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 6381d98

Please sign in to comment.