Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,19 @@ public void creates_JavaPackages() {
}

private JavaClasses importJavaBase() {
return new ClassFileImporter()
.withImportOption(location ->
// before Java 9 packages like java.lang were in rt.jar
location.contains("rt.jar") ||
// from Java 9 on those packages were in a JRT with name 'java.base'
(location.asURI().getScheme().equals("jrt") && location.contains("java.base"))
)
.importClasspath();
return new ClassFileImporter().withImportOption(location -> !isSunPackage(location) && (
// before Java 9 packages like java.lang were in rt.jar;
location.contains("rt.jar") ||
// from Java 9 on those packages were in a JRT with name 'java.base'
(location.asURI().getScheme().equals("jrt") && location.contains("java.base"))
)).importClasspath();
}

private ImportOption importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath() {
return location -> {
if (isSunPackage(location)) {
return false;
}
if (!location.isArchive()) {
return true;
}
Expand All @@ -200,4 +201,13 @@ private ImportOption importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath() {
return location.asURI().getScheme().equals("jrt") && location.contains("java.base");
};
}

/**
* Importing the full classpath may give thousands of classes in {@link sun} and (especially for Java 8) {@link com.sun} packages.
* Importing those would increase the memory footprint tremendously, but not give an additional benefit for the test,
* so it is convenient to ignore those.
*/
private static boolean isSunPackage(Location location) {
return location.contains("/sun/");
}
}
63 changes: 31 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,47 @@ ext {
googleRelocationPackage = "${thirdPartyRelocationPackage}.com.google"

dependency = [
asm : [group: 'org.ow2.asm', name: 'asm', version: '9.7.1'],
guava : [group: 'com.google.guava', name: 'guava', version: '33.3.1-jre'],
addGuava : { dependencyHandler ->
asm : [group: 'org.ow2.asm', name: 'asm', version: '9.8'],
guava : [group: 'com.google.guava', name: 'guava', version: '33.4.8-jre'],
addGuava : { dependencyHandler ->
dependencyHandler(dependency.guava) {
exclude module: 'listenablefuture'
exclude module: 'jsr305'
exclude module: 'checker-qual'
exclude module: 'jspecify'
exclude module: 'error_prone_annotations'
exclude module: 'j2objc-annotations'
}
},
slf4j : [group: 'org.slf4j', name: 'slf4j-api', version: '2.0.16'],
log4j_api : [group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.24.1'],
log4j_core : [group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.24.1'],
log4j_slf4j : [group: 'org.apache.logging.log4j', name: 'log4j-slf4j2-impl', version: '2.24.1'],
slf4j : [group: 'org.slf4j', name: 'slf4j-api', version: '2.0.17'],
log4j_api : [group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.24.3'],
log4j_core : [group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.24.3'],
log4j_slf4j : [group: 'org.apache.logging.log4j', name: 'log4j-slf4j2-impl', version: '2.24.3'],

junit4 : [group: 'junit', name: 'junit', version: '4.13.2'],
junit5JupiterApi : [group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.2'],
junit5JupiterEngine : [group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.11.2'],
junit5VintageEngine : [group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.11.2'],
junitPlatform : [group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.11.2'],
junitPlatformCommons: [group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.11.2'],
junitPlatformEngine : [group: 'org.junit.platform', name: 'junit-platform-engine', version: '1.11.2'],
hamcrest : [group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'],
junit_dataprovider : [group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.11.0'],
mockito : [group: 'org.mockito', name: 'mockito-core', version: '4.11.0'], // mockito 5 requires Java 11
mockito_junit5 : [group: 'org.mockito', name: 'mockito-junit-jupiter', version: '4.6.1'],
assertj : [group: 'org.assertj', name: 'assertj-core', version: '3.26.3'],
assertj_guava : [group: 'org.assertj', name: 'assertj-guava', version: '3.26.3'],
junit4 : [group: 'junit', name: 'junit', version: '4.13.2'],
junit5Jupiter : [group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.12.2'],
junit5VintageEngine : [group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.12.2'],
junitPlatform : [group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.12.2'],
junitPlatformCommons : [group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.12.2'],
junitPlatformEngine : [group: 'org.junit.platform', name: 'junit-platform-engine', version: '1.12.2'],
junitPlatformLauncher: [group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.12.2'],
hamcrest : [group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'],
junit_dataprovider : [group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.11.0'],
mockito : [group: 'org.mockito', name: 'mockito-core', version: '4.11.0'], // mockito 5 requires Java 11
mockito_junit5 : [group: 'org.mockito', name: 'mockito-junit-jupiter', version: '4.6.1'],
assertj : [group: 'org.assertj', name: 'assertj-core', version: '3.27.3'],
assertj_guava : [group: 'org.assertj', name: 'assertj-guava', version: '3.27.3'],

// Dependencies for example projects / tests
javaxAnnotationApi : [group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'],
springBeans : [group: 'org.springframework', name: 'spring-beans', version: '5.3.23'],
springBootLoader : [group: 'org.springframework.boot', name: 'spring-boot-loader', version: '2.7.13'],
jakartaInject : [group: 'jakarta.inject', name: 'jakarta.inject-api', version: '2.0.1'],
jakartaAnnotations : [group: 'jakarta.annotation', name: 'jakarta.annotation-api', version: '2.1.1'],
guice : [group: 'com.google.inject', name: 'guice', version: '5.1.0'],
javaxAnnotationApi : [group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'],
springBeans : [group: 'org.springframework', name: 'spring-beans', version: '5.3.23'],
springBootLoader : [group: 'org.springframework.boot', name: 'spring-boot-loader', version: '2.7.13'],
jakartaInject : [group: 'jakarta.inject', name: 'jakarta.inject-api', version: '2.0.1'],
jakartaAnnotations : [group: 'jakarta.annotation', name: 'jakarta.annotation-api', version: '2.1.1'],
guice : [group: 'com.google.inject', name: 'guice', version: '5.1.0'],
// NOTE: The pure javaee-api dependencies are crippled, so to run any test we need to choose a full implementation provider
geronimoEjb : [group: 'org.apache.geronimo.specs', name: 'geronimo-ejb_3.1_spec', version: '1.0.2'],
geronimoJpa : [group: 'org.apache.geronimo.specs', name: 'geronimo-jpa_2.0_spec', version: '1.1'],
jodaTime : [group: 'joda-time', name: 'joda-time', version: '2.12.7'],
joox : [group: 'org.jooq', name: 'joox-java-6', version: '1.6.0']
geronimoEjb : [group: 'org.apache.geronimo.specs', name: 'geronimo-ejb_3.1_spec', version: '1.0.2'],
geronimoJpa : [group: 'org.apache.geronimo.specs', name: 'geronimo-jpa_2.0_spec', version: '1.1'],
jodaTime : [group: 'joda-time', name: 'joda-time', version: '2.12.7'],
joox : [group: 'org.jooq', name: 'joox-java-6', version: '1.6.0']
]

minSupportedJavaVersion = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ abstract class ArchUnitTestExtension {
ext.archUnitTest = extensions.create('archUnitTest', ArchUnitTestExtension)

dependencies {
testImplementation dependency.junit5JupiterApi
testImplementation dependency.junit5Jupiter

testRuntimeOnly dependency.junit5JupiterEngine
testRuntimeOnly dependency.junit5VintageEngine
testRuntimeOnly dependency.junitPlatformLauncher
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I fully get this, why exactly does this break in archunit-3rd-party-test? AFAIS that module doesn't even have JUnit Jupiter tests, no? 🤔
Not sure we should really add this globally, even if it solves that symptom, in particular if it's only that one specific test module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen the

org.junit.platform.commons.JUnitException: OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars on the classpath/module path.

occur with the upgrade to JUnit 5.12 in other projects, too. I thought it was some kind of version conflict. Do you know what Gradle's useJUnitPlatform actually provides? Some Gradle upgrade notes mention:

If using JUnit 5, an explicit runtimeOnly dependency on junit-platform-launcher is required in addition to the existing implementation dependency on the test engine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and it turns out that not only archunit-3rd-party-test fails with this JUnitException – that just happened to be the first module where I saw the error. 🙄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've dropped the misleading reference to archunit-3rd-party-test from the commit message.
If you prefer to understand the change with JUnit 5.12 better, we could also drop that update entirely from this PR, and have it in a separate one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, if the docs say that you need that platform launcher dependency, then that's good enough for me 😉 Thanks a lot for the explanation!

testRuntimeOnly dependency.log4j_slf4j
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.11.2</version>
<version>1.12.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/resources/release_check/archunit.pom
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
<version>2.0.17</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Loading