Java: Add test for multi-module projects with different Java versions

This commit is contained in:
idrissrio
2025-10-09 14:05:11 +02:00
parent f1076b9eb1
commit 6b890eaf94
7 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>maven-multimodule-test-java-version</artifactId>
<version>1.0</version>
</parent>
<artifactId>main-module</artifactId>
</project>

View File

@@ -0,0 +1,7 @@
package com.example;
public class App {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>maven-multimodule-test-java-version</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<modules>
<module>main-module</module>
<module>test-module</module>
</modules>
</project>

View File

@@ -0,0 +1,7 @@
main-module/pom.xml
main-module/src/main/java/com/example/App.java
main-module/target/maven-archiver/pom.properties
pom.xml
test-module/pom.xml
test-module/src/main/java/com/example/tests/TestUtils.java
test-module/target/maven-archiver/pom.properties

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>maven-multimodule-test-java-version</artifactId>
<version>1.0</version>
</parent>
<artifactId>test-module</artifactId>
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
</project>

View File

@@ -0,0 +1,12 @@
package com.example.tests;
// Requires Java 21: switch with pattern matching and guards
public class TestUtils {
public static String analyze(Object obj) {
return switch (obj) {
case String s when s.length() > 5 -> "long";
case String s -> "short";
default -> "other";
};
}
}

View File

@@ -0,0 +1,2 @@
def test(codeql, java):
codeql.database.create()