Skip to content

Commit 291ca9c

Browse files
authored
Merge pull request #73 from cfmleditor/claude/jdk11-jdk21-artifacts
Publish a Java 11 main artifact and a jdk21 classifier
2 parents d4f8fb0 + 6068ce0 commit 291ca9c

3 files changed

Lines changed: 114 additions & 6 deletions

File tree

‎.github/workflows/gradle.yml‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,34 @@ on:
1010
jobs:
1111
gradle:
1212
strategy:
13+
fail-fast: false
1314
matrix:
1415
os: [ubuntu-latest, macos-latest, windows-latest]
16+
# 11 is the baseline the published main artifact targets, 21 the runtime most
17+
# consumers are on. Running the suite on both is the only way to catch a Java 11
18+
# problem that compiling to 11 on a 21 JDK cannot see.
19+
java-version: [11, 21]
1520
runs-on: ${{ matrix.os }}
1621
steps:
1722
- name: Checkout
1823
uses: actions/checkout@v4
1924

20-
- name: Set up JDK 21
25+
# Both JDKs are installed. The last entry becomes JAVA_HOME, so Gradle's daemon
26+
# always runs on 21 -- the bnd OSGi plugin is class file 61 and cannot load on an
27+
# 11 JVM. The matrix JDK is picked up by the toolchain for compiling and running
28+
# the tests, which is the part that needs to happen on Java 11.
29+
- name: Set up JDK ${{ matrix.java-version }} and 21
2130
uses: actions/setup-java@v4
2231
with:
2332
distribution: temurin
24-
java-version: 21
33+
java-version: |
34+
${{ matrix.java-version }}
35+
21
2536
2637
- name: Setup Gradle
2738
uses: gradle/actions/setup-gradle@v3
2839
with:
2940
gradle-version: wrapper
3041

3142
- name: Build with Gradle
32-
run: ./gradlew build
43+
run: ./gradlew build -PjavaTestVersion=${{ matrix.java-version }}

‎build.gradle‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,22 @@ subprojects {
133133
}
134134
}
135135

136-
sourceCompatibility = 21
137-
targetCompatibility = 21
136+
// Bytecode stays at 11 to match the Maven main artifact, whatever JDK is running.
137+
// The published jdk21 classifier is produced by Maven, which is what publishes.
138+
sourceCompatibility = 11
139+
targetCompatibility = 11
140+
141+
// -PjavaTestVersion selects the JDK that compiles and runs the tests, so CI can
142+
// exercise the same Java 11 bytecode on an 11 and a 21 runtime. Gradle itself keeps
143+
// running on the launcher JDK: the bnd OSGi plugin is class file 61 and throws
144+
// UnsupportedClassVersionError if the daemon is on Java 11, so the toolchain has to
145+
// move rather than the whole build.
146+
java {
147+
toolchain {
148+
languageVersion = JavaLanguageVersion.of(
149+
(project.findProperty('javaTestVersion') ?: '21') as Integer)
150+
}
151+
}
138152
tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }
139153

140154
task sourcesJar(type: Jar) {

‎pom.xml‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@
5757
<properties>
5858
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5959

60-
<maven.compiler.release>21</maven.compiler.release>
60+
<!-- The main artifact is Java 11 so it loads on every supported runtime; the
61+
jdk21 classifier below is the same source compiled at 21. See the jdk21
62+
executions in build/plugins. -->
63+
<maven.compiler.release>11</maven.compiler.release>
64+
<jdk21.release>21</jdk21.release>
6165

6266
<jacoco.version>0.8.12</jacoco.version>
6367
<!-- jacoco:prepare-agent overwrites this at build time with the -javaagent setting.
@@ -133,6 +137,85 @@
133137
</execution>
134138
</executions>
135139
</plugin>
140+
<!-- Two artifacts from one source tree. default-compile emits Java 11 into
141+
target/classes for the main jar; compile-jdk21 emits Java 21 into
142+
target/classes-jdk21 for the jdk21 classifier. The resource copy is
143+
needed because maven-jar-plugin takes a single classesDirectory, and
144+
that directory holds only .class files, so without it the classified
145+
jar would ship without cfml.dictionary's XML.
146+
147+
The copy must stay at process-classes and not move later. Setting
148+
outputDirectory on a compiler execution leaks into what the reactor
149+
hands dependent modules, so cfml.parsing's tests resolve
150+
cfml.dictionary to classes-jdk21. Copy the resources after the tests
151+
run and all 326 fail with "Problem loading dictionaryconfig.xml",
152+
which reads like a missing resource rather than a phase ordering
153+
problem. -->
154+
<plugin>
155+
<groupId>org.apache.maven.plugins</groupId>
156+
<artifactId>maven-compiler-plugin</artifactId>
157+
<version>3.13.0</version>
158+
<executions>
159+
<execution>
160+
<id>compile-jdk21</id>
161+
<phase>compile</phase>
162+
<goals>
163+
<goal>compile</goal>
164+
</goals>
165+
<configuration>
166+
<release>${jdk21.release}</release>
167+
<outputDirectory>${project.build.directory}/classes-jdk21</outputDirectory>
168+
</configuration>
169+
</execution>
170+
</executions>
171+
</plugin>
172+
<plugin>
173+
<groupId>org.apache.maven.plugins</groupId>
174+
<artifactId>maven-resources-plugin</artifactId>
175+
<version>3.3.1</version>
176+
<executions>
177+
<execution>
178+
<id>copy-resources-jdk21</id>
179+
<phase>process-classes</phase>
180+
<goals>
181+
<goal>copy-resources</goal>
182+
</goals>
183+
<configuration>
184+
<outputDirectory>${project.build.directory}/classes-jdk21</outputDirectory>
185+
<resources>
186+
<resource>
187+
<directory>${project.build.outputDirectory}</directory>
188+
<excludes>
189+
<exclude>**/*.class</exclude>
190+
</excludes>
191+
</resource>
192+
</resources>
193+
</configuration>
194+
</execution>
195+
</executions>
196+
</plugin>
197+
<plugin>
198+
<groupId>org.apache.maven.plugins</groupId>
199+
<artifactId>maven-jar-plugin</artifactId>
200+
<version>3.4.1</version>
201+
<executions>
202+
<execution>
203+
<id>jar-jdk21</id>
204+
<phase>package</phase>
205+
<goals>
206+
<goal>jar</goal>
207+
</goals>
208+
<configuration>
209+
<classifier>jdk21</classifier>
210+
<classesDirectory>${project.build.directory}/classes-jdk21</classesDirectory>
211+
<!-- The parent is pom-packaged and compiles nothing, so its
212+
classes-jdk21 is empty. Without this it still emits and
213+
deploys a spurious cfparser-VERSION-jdk21.jar. -->
214+
<skipIfEmpty>true</skipIfEmpty>
215+
</configuration>
216+
</execution>
217+
</executions>
218+
</plugin>
136219
<plugin>
137220
<groupId>org.jacoco</groupId>
138221
<artifactId>jacoco-maven-plugin</artifactId>

0 commit comments

Comments
 (0)