Skip to content

Conversation

@dnestoro
Copy link
Contributor

@dnestoro dnestoro commented Apr 4, 2025

Fixes: #601 and #562

I tested this on the java-application-with-resources sample. If I set <scope> of org.apache.commons to provided:

  • without this fix classpath looks like this:

[INFO] Executing: /.sdkman/candidates/java/21.0.4-graal/bin/native-image -cp /native-build-tools/samples/java-application-with-resources/target/classes:/native-build-tools/samples/java-application-with-resources/target/test-classes:/native-build-tools/samples/java-application-with-resources/src/test/resources:/.m2/repository/org/junit/jupiter/junit-jupiter/5.10.0/junit-jupiter-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar:/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar:/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.10.0/junit-jupiter-params-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar:/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar:/.m2/repository/org/graalvm/buildtools/native-maven-plugin/0.10.7-SNAPSHOT/native-maven-plugin-0.10.7-SNAPSHOT.jar:/.m2/repository/org/graalvm/buildtools/utils/0.10.7-SNAPSHOT/utils-0.10.7-SNAPSHOT.jar:/.m2/repository/org/graalvm/buildtools/graalvm-reachability-metadata/0.10.7-SNAPSHOT/graalvm-reachability-metadata-0.10.7-SNAPSHOT.jar:/.m2/repository/org/graalvm/buildtools/junit-platform-native/0.10.7-SNAPSHOT/junit-platform-native-0.10.7-SNAPSHOT.jar:/.m2/repository/org/junit/platform/junit-platform-console/1.10.0/junit-platform-console-1.10.0.jar:/.m2/repository/org/junit/platform/junit-platform-reporting/1.10.0/junit-platform-reporting-1.10.0.jar:/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/.m2/repository/org/junit/platform/junit-platform-launcher/1.10.0/junit-platform-launcher-1.10.0.jar:/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar:/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter/5.10.0/junit-jupiter-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.10.0/junit-jupiter-params-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar --no-fallback -o /native-build-tools/samples/java-application-with-resources/target/native-tests -Djunit.platform.listeners.uid.tracking.output.dir=/native-build-tools/samples/java-application-with-resources/target/test-ids --features=org.graalvm.junit.platform.JUnitPlatformFeature -H:ConfigurationFileDirectories=/native-build-tools/samples/java-application-with-resources/target/native/generated/generateTestResourceConfig org.graalvm.junit.platform.NativeImageJUnitLauncher

and there is no org.apache.commons dependency.

  • with this fix classpath looks like this:

[INFO] Executing: /.sdkman/candidates/java/21.0.4-graal/bin/native-image -cp /native-build-tools/samples/java-application-with-resources/target/classes:/native-build-tools/samples/java-application-with-resources/target/test-classes:/native-build-tools/samples/java-application-with-resources/src/test/resources:/.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter/5.10.0/junit-jupiter-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar:/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar:/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.10.0/junit-jupiter-params-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar:/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar:/.m2/repository/org/graalvm/buildtools/native-maven-plugin/0.10.7-SNAPSHOT/native-maven-plugin-0.10.7-SNAPSHOT.jar:/.m2/repository/org/graalvm/buildtools/utils/0.10.7-SNAPSHOT/utils-0.10.7-SNAPSHOT.jar:/.m2/repository/org/graalvm/buildtools/graalvm-reachability-metadata/0.10.7-SNAPSHOT/graalvm-reachability-metadata-0.10.7-SNAPSHOT.jar:/.m2/repository/org/graalvm/buildtools/junit-platform-native/0.10.7-SNAPSHOT/junit-platform-native-0.10.7-SNAPSHOT.jar:/.m2/repository/org/junit/platform/junit-platform-console/1.10.0/junit-platform-console-1.10.0.jar:/.m2/repository/org/junit/platform/junit-platform-reporting/1.10.0/junit-platform-reporting-1.10.0.jar:/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/.m2/repository/org/junit/platform/junit-platform-launcher/1.10.0/junit-platform-launcher-1.10.0.jar:/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar:/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter/5.10.0/junit-jupiter-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.10.0/junit-jupiter-params-5.10.0.jar:/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar --no-fallback -o /native-build-tools/samples/java-application-with-resources/target/native-tests -Djunit.platform.listeners.uid.tracking.output.dir=/native-build-tools/samples/java-application-with-resources/target/test-ids --features=org.graalvm.junit.platform.JUnitPlatformFeature -H:ConfigurationFileDirectories=/native-build-tools/samples/java-application-with-resources/target/native/generated/generateTestResourceConfig org.graalvm.junit.platform.NativeImageJUnitLauncher

and we can see that there is an entry fororg.apache.commons (/.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar)

NOTE: when I run mvn -Pnative package -DskipNativeTests classpath doesn't have org.apache.commons dependency if it has <scope>provided</scope>:

[INFO] Executing: /.sdkman/candidates/java/21.0.4-graal/bin/native-image -cp /native-build-tools/samples/java-application-with-resources/target/maven-app-with-tests.jar --no-fallback -o /native-build-tools/samples/java-application-with-resources/target/example-app -H:ConfigurationFileDirectories=/native-build-tools/samples/java-application-with-resources/target/native/generated/generateTestResourceConfig,/native-build-tools/samples/java-application-with-resources/target/native/generated/generateResourceConfig -H:ConfigurationFileDirectories=/native-build-tools/samples/java-application-with-resources/target/native/generated/generateTestResourceConfig,/native-build-tools/samples/java-application-with-resources/target/native/generated/generateResourceConfig -H:ConfigurationFileDirectories=/native-build-tools/samples/java-application-with-resources/target/native/generated/generateTestResourceConfig,/native-build-tools/samples/java-application-with-resources/target/native/generated/generateResourceConfig org.graalvm.demo.Application

(without explicitly defined <scope> the dependency appears on classpath)

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 4, 2025
@dnestoro dnestoro requested a review from melix April 4, 2025 13:58
@dnestoro dnestoro marked this pull request as ready for review April 4, 2025 13:58
@dnestoro dnestoro self-assigned this Apr 11, 2025
melix
melix previously approved these changes Apr 11, 2025
Copy link
Collaborator

@melix melix left a comment

Choose a reason for hiding this comment

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

Would be good to add a test for this.

@dnestoro dnestoro requested a review from melix April 16, 2025 13:24
@dnestoro dnestoro merged commit ea84906 into master Apr 23, 2025
159 checks passed
@dnestoro dnestoro deleted the dnestoro/include-dependencies-with-scope-provided branch April 23, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Image Maven Plugin should include provided dependencies for testing

2 participants