Skip to content

Commit 96f57b2

Browse files
authored
Merge pull request #20615 from github/idrissrio/java-jdk
Java: Add test for multi-module projects with different Java versions
2 parents 8668473 + d916ebd commit 96f57b2

File tree

26 files changed

+343
-0
lines changed

26 files changed

+343
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>maven-add-exports-module-flags</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<name>maven-add-exports-module-flags</name>
11+
<description>Test case: Project using --add-exports. Autobuilder should detect this and use --source/--target.</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<java.version>11</java.version>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<version>3.11.0</version>
24+
<configuration>
25+
<source>${java.version}</source>
26+
<target>${java.version}</target>
27+
<compilerArgs>
28+
<arg>--add-exports</arg>
29+
<arg>jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
30+
<arg>--add-exports</arg>
31+
<arg>jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
32+
<arg>--add-exports</arg>
33+
<arg>jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
34+
<arg>--add-exports</arg>
35+
<arg>jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
36+
</compilerArgs>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
</project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pom.xml
2+
src/main/java/com/example/CompilerUser.java
3+
target/maven-archiver/pom.properties
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example;
2+
3+
import com.sun.tools.javac.api.JavacTool;
4+
5+
/**
6+
* Simple class that uses JDK compiler internals.
7+
* This requires --add-exports flags to compile.
8+
*/
9+
public class CompilerUser {
10+
public static void main(String[] args) {
11+
// Use JavacTool from jdk.compiler module
12+
JavacTool tool = JavacTool.create();
13+
System.out.println("Compiler tool: " + tool.getClass().getName());
14+
}
15+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test(codeql, java, actions_toolchains_file):
2+
codeql.database.create(_env={"LGTM_INDEX_MAVEN_TOOLCHAINS_FILE": str(actions_toolchains_file)})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>maven-execution-specific-java-version</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<name>maven-execution-specific-java-version</name>
11+
<description>Test case: Project with execution-specific Java versions (Java 11 for main, Java 17 for test). Maven.java should detect the highest version (17) and use it for compilation.</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-compiler-plugin</artifactId>
22+
<version>3.13.0</version>
23+
<executions>
24+
<!-- Compilation for src/main/java -->
25+
<execution>
26+
<id>default-compile</id>
27+
<phase>compile</phase>
28+
<goals>
29+
<goal>compile</goal>
30+
</goals>
31+
<configuration>
32+
<release>11</release> <!-- Java 11 for main -->
33+
</configuration>
34+
</execution>
35+
36+
<!-- Compilation for src/test/java -->
37+
<execution>
38+
<id>default-testCompile</id>
39+
<phase>test-compile</phase>
40+
<goals>
41+
<goal>testCompile</goal>
42+
</goals>
43+
<configuration>
44+
<release>17</release> <!-- Java 17 for test -->
45+
</configuration>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pom.xml
2+
src/main/java/com/example/App.java
3+
src/test/java/com/example/AppTest.java
4+
target/maven-archiver/pom.properties
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example;
2+
3+
public class App {
4+
public static void main(String[] args) {
5+
var message = "Hello World! Running on Java " + System.getProperty("java.version");
6+
System.out.println(message);
7+
}
8+
9+
public String getMessage() {
10+
return "Hello from App";
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example;
2+
3+
public class AppTest {
4+
public static void main(String[] args) {
5+
var text = """
6+
Hello
7+
World
8+
""";
9+
System.out.println(text.strip());
10+
}
11+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test(codeql, java, actions_toolchains_file):
2+
codeql.database.create(_env={"LGTM_INDEX_MAVEN_TOOLCHAINS_FILE": str(actions_toolchains_file)})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>maven-java16-with-higher-jdk</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<name>maven-java16-with-higher-jdk</name>
11+
<description>Test case: Java 16 target when only Java 17+ is available.</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<java.version>16</java.version>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<version>3.11.0</version>
24+
<configuration>
25+
<release>${java.version}</release>
26+
</configuration>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>

0 commit comments

Comments
 (0)