Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: maven archetypes fail with maven 3.9.6 #1031

Closed
barchetta opened this issue Mar 28, 2024 · 2 comments
Closed

2.x: maven archetypes fail with maven 3.9.6 #1031

barchetta opened this issue Mar 28, 2024 · 2 comments
Assignees
Labels
2.x Applies to the 2.x branch archetype bug Something isn't working
Milestone

Comments

@barchetta
Copy link
Member

barchetta commented Mar 28, 2024

With maven 3.9.6 run

mvn -U archetype:generate -DinteractiveMode=false \
    -DarchetypeGroupId=io.helidon.archetypes \
    -DarchetypeArtifactId=helidon-quickstart-mp \
    -DarchetypeVersion=2.6.6 \
    -DgroupId=io.helidon.examples \
    -DartifactId=helidon-quickstart-mp \
    -Dpackage=io.helidon.examples.quickstart.mp

It fails with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate (default-cli) on project standalone-pom: 
Execution default-cli of goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate failed: 
A required class was missing while executing org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate: 
com/github/mustachejava/MustacheFactory

Stack from -X

Caused by: java.lang.ClassNotFoundException: com.github.mustachejava.MustacheFactory
    at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
    at java.lang.Class.getDeclaredConstructors0 (Native Method)
    at java.lang.Class.privateGetDeclaredConstructors (Class.java:3137)
    at java.lang.Class.getConstructor0 (Class.java:3342)
    at java.lang.Class.getConstructor (Class.java:2151)
    at io.helidon.build.archetype.maven.postgenerate.EngineFacade.generate (EngineFacade.java:134)

If I run with maven 3.8.2 all is well.
If I run a Helidon 3.x archetype (with maven 3.9.6) all is well.

@barchetta barchetta added bug Something isn't working archetypes 2.x Applies to the 2.x branch labels Mar 28, 2024
@romain-grecourt
Copy link
Contributor

romain-grecourt commented Mar 28, 2024

This is because the dependency resolution of io.helidon.build-tools:helidon-archetype-engine:2.3.7 fails silently and we end-up with a class-loader with just one URL (the archetype-engine JAR file).

  • The dependency resolution fails because the effective model resolution of helidon-archetype-engine fails
  • helidon-archetype-engine inherits helidon-build-tools-project which imports helidon-bom:0.9.0 which has a profile activated by a jdk version
  • The active profile check fails because the aether repository session does not have system properties
org.apache.maven.model.building.ModelBuildingException: 1 problem was encountered while building the effective model for io.helidon.build-tools.archetype:helidon-archetype-engine:2.3.7
[ERROR] Failed to determine Java version for profile jdk9+ @ io.helidon:helidon-project:0.9.0

	at org.apache.maven.model.building.DefaultModelProblemCollector.newModelBuildingException(DefaultModelProblemCollector.java:176)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:508)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:410)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:243)
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:284)
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:175)
	at org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegate.collectDependencies(DependencyCollectorDelegate.java:179)
	at org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:87)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:328)
	at io.helidon.build.archetype.maven.postgenerate.Aether.resolveDependencies(Aether.java:221)

String version = context.getSystemProperties().get("java.version");

if (version == null || version.length() <= 0) {
    problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
            .setMessage("Failed to determine Java version for profile " + profile.getId())
            .setLocation(activation.getLocation("jdk")));
    return false;
}

See https://github.com/apache/maven/blob/maven-3.9.5/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java#L68

@romain-grecourt romain-grecourt self-assigned this Mar 28, 2024
@romain-grecourt romain-grecourt added this to the 2.3.9 milestone Mar 28, 2024
romain-grecourt added a commit to romain-grecourt/helidon-build-tools that referenced this issue Mar 28, 2024
@romain-grecourt
Copy link
Contributor

romain-grecourt commented Mar 28, 2024

This is caused by a change in Maven 3.9.0 in this commit

We use MavenRepositorySystemUtils.newSession() to create a new RepositorySystemSession and pre 3.9.0 the session had system properties populated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Applies to the 2.x branch archetype bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants