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

Group all dependencies in the parent pom.xml #40

Merged
merged 3 commits into from
Sep 5, 2023

Conversation

jmesnil
Copy link
Member

@jmesnil jmesnil commented Aug 17, 2023

This will simplify the maintenance of the archetypes.

I've also renamed version.jboss.bom to version.wildfly.bom as this is the version that controls the org.wildfly.boms dependencies.

@jmesnil jmesnil requested a review from jamezp August 17, 2023 15:29
@jmesnil
Copy link
Member Author

jmesnil commented Aug 17, 2023

@jamezp Wdyt? On one hand, there is a single place to update any dependencies/plugins but on the other hand, the creation of the archetypes is a bit more complex (their pom.xml is filtered while the rest of their resources is not)

@WolfgangHG
Copy link
Contributor

Just for my understanding: when we build the archetype, the property values in archetype-resources/pom.xml (e.g. ${version.wildfly.bom} ) are taken from "org.wildfly.archetype:wildfly-archetypes" pom.xml and written to the archetype-resources/pom.xml? The latter is no longer a file in git, but is generated every time?

@jmesnil
Copy link
Member Author

jmesnil commented Aug 18, 2023

@WolfgangHG not exactly.

The first part is correct: the property values are stored in the parent pom.xml

The archetype-resources pom.xml is still in Git but in a separate source tree (eg wildfly-jakartaee-ear-archetype/src/main/resources-filtered/archetype-resources/pom.xml).
When the archetypes are built, this pom.xml is filtered with the property values from the parent pom (so its own version.wildfly.bom will have the value 29.0.0.Final).
The reason of this structure is that we want to evaluate some property values when we built the archetype (for the versions) and keep others that will be evaluate when the project is generated by the archetypes (eg rootArtifactId) . The latter properties are escaped from filtering by prepending a /.

Does that clarify it? (If this PR is approved, I'll add this comment to the archetypes README so that we know why the projects are structured this way.)

@jmesnil jmesnil force-pushed the dependencies_refactoring branch 2 times, most recently from 441572e to e06ee95 Compare August 18, 2023 07:11
@WolfgangHG
Copy link
Contributor

OK, I hope I got it ;-). Would have to see it myself, but not before late this evening...
Could you document this in some Readme.md? This would be hard to track otherwise.

rename version.jboss.bom to version.wildfly.bom

Signed-off-by: Jeff Mesnil <jmesnil@redhat.com>
@jmesnil
Copy link
Member Author

jmesnil commented Aug 18, 2023

@WolfgangHG There is no hurry to do that change but that was the last thing I was missing to lower the maintenance of the archetypes :)

I amended the PR to add some documentation (https://github.com/wildfly/wildfly-archetypes/compare/e06ee95a3f72c312a3f30ae87844fe7a7d8b36b9..fc90c2eaccd858061018847ca7e2b1553dd7cc4b)

@WolfgangHG
Copy link
Contributor

WolfgangHG commented Aug 18, 2023

@jmesnil Wait - there is something strange...
I cannot create a project from the EAR archetype 30.0.0.Final-SNAPSHOT.

This maven command fails:
mvn archetype:generate -DgroupId=foo.bar -DartifactId=multi -Dversion=0.1-SNAPSHOT -Dpackage=foo.bar.multi -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-jakartaee-ear-archetype -DarchetypeVersion=30.0.0.Final-SNAPSHOT -DinteractiveMode=false -DarchetypeCatalog=local -X

Error:

[INFO] Generating project in Batch mode
[DEBUG] Getting archetypes from catalog: C:\Users\USERNAME\.m2\repository\archetype-catalog.xml
[INFO] Archetype repository not defined. Using the one from [org.wildfly.archetype:wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT] found in catalog local
[DEBUG] Not found archetype org.wildfly.archetype:wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT in cache
[DEBUG] Could not find metadata org.wildfly.archetype:wildfly-archetypes:30.0.0.Final-SNAPSHOT/maven-metadata.xml in local (C:\Users\USERNAME\.m2\repository)
[DEBUG] Resolving artifact org.wildfly.archetype:wildfly-archetypes:pom:30.0.0.Final-SNAPSHOT from [central (https://repo.maven.apache.org/maven2, default, releases)]
[DEBUG] Archetype org.wildfly.archetype:wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT doesn't exist
org.apache.maven.archetype.downloader.DownloadException: Error downloading org.wildfly.archetype:wildfly-jakartaee-ear-archetype:jar:30.0.0.Final-SNAPSHOT.

It works for the 29.0.0.Final-SNAPSHOT version:

[INFO] Generating project in Batch mode
[DEBUG] Getting archetypes from catalog: C:\Users\knuffi\.m2\repository\archetype-catalog.xml
[INFO] Archetype repository not defined. Using the one from [org.wildfly.archetype:wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT] found in catalog local
[DEBUG] Not found archetype org.wildfly.archetype:wildfly-jakartaee-ear-archetype:29.0.0.Final-SNAPSHOT in cache
[DEBUG] Found archetype org.wildfly.archetype:wildfly-jakartaee-ear-archetype:29.0.0.Final-SNAPSHOT in cache: C:\Users\knuffi\.m2\repository\org\wildfly\archetype\wildfly-jakartaee-ear-archetype\29.0.0.Final-SNAPSHOT\wildfly-jakartaee-ear-archetype-29.0.0.Final-SNAPSHOT.jar
[DEBUG] checking fileset archetype status on C:\Users\knuffi\.m2\repository\org\wildfly\archetype\wildfly-jakartaee-ear-archetype\29.0.0.Final-SNAPSHOT\wildfly-jakartaee-ear-archetype-29.0.0.Final-SNAPSHOT.jar
[DEBUG] Searching for META-INF/maven/archetype-metadata.xml inside C:\Users\knuffi\.m2\repository\org\wildfly\archetype\wildfly-jakartaee-ear-archetype\29.0.0.Final-SNAPSHOT\wildfly-jakartaee-ear-archetype-29.0.0.Final-SNAPSHOT.jar

The jar file for the archetype is in the repository and "archetype-catalog.xml" contains. But something is wrong with it, and I have no idea what. Might also be caused by the previous change to the directory names.

The log for the successful checks from your pull request also seems to have an issue. See the line where it falls back to "29.0.0.Final" from remote repository.

2023-08-18T08:34:22.0889453Z env:
2023-08-18T08:34:22.0889763Z   JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.8-7/x64
2023-08-18T08:34:22.0890167Z   JAVA_HOME_17_X64: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.8-7/x64
2023-08-18T08:34:22.0890517Z   ARCHETYPE_VERSION: 30.0.0.Final-SNAPSHOT
2023-08-18T08:34:22.0890776Z   WILDFLY_VERSION: 29.0.0.Final
2023-08-18T08:34:22.0891143Z   JBOSS_HOME: /home/runner/work/wildfly-archetypes/wildfly-archetypes/wildfly-29.0.0.Final
2023-08-18T08:34:22.0891485Z ##[endgroup]
2023-08-18T08:34:22.0987050Z creating test project directory
2023-08-18T08:34:22.1005310Z generate project from archetype.
2023-08-18T08:34:23.1372114Z [INFO] Scanning for projects...
2023-08-18T08:34:23.4378661Z [INFO] 
2023-08-18T08:34:23.4384074Z [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
2023-08-18T08:34:23.4389554Z [INFO] Building Maven Stub Project (No POM) 1
2023-08-18T08:34:23.4412144Z [INFO] --------------------------------[ pom ]---------------------------------
2023-08-18T08:34:23.4459603Z [INFO] 
2023-08-18T08:34:23.4465672Z [INFO] >>> maven-archetype-plugin:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
2023-08-18T08:34:23.4470491Z [INFO] 
2023-08-18T08:34:23.4473106Z [INFO] <<< maven-archetype-plugin:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
2023-08-18T08:34:23.4474906Z [INFO] 
2023-08-18T08:34:23.4486208Z [INFO] 
2023-08-18T08:34:23.4488862Z [INFO] --- maven-archetype-plugin:3.2.1:generate (default-cli) @ standalone-pom ---
2023-08-18T08:34:24.1513322Z [INFO] Generating project in Batch mode
2023-08-18T08:34:25.2601418Z [INFO] Archetype repository not defined. Using the one from [org.wildfly.archetype:wildfly-jakartaee-ear-archetype:29.0.0.Final] found in catalog remote
2023-08-18T08:34:25.2828272Z [INFO] ----------------------------------------------------------------------------
2023-08-18T08:34:25.2832942Z [INFO] Using following parameters for creating project from Archetype: wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT

The "webapp" archetype works for me.

@WolfgangHG
Copy link
Contributor

I think we should add -DarchetypeCatalog=local to the scripts "runtest_xxx.bat/sh" to prevent the fallback to the previous release version.

Copy link
Member

@jamezp jamezp left a comment

Choose a reason for hiding this comment

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

I think this looks good. The only question I added about failsafe vs surefire is just a minor question.

Comment on lines +83 to +87
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe.plugin}</version>
</plugin>
Copy link
Member

Choose a reason for hiding this comment

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

Should this be surefire or failsafe? I don't have a strong opinion, I'm just curious :)

@WolfgangHG
Copy link
Contributor

@jamezp The integration tests for the EAR must be "surefire", see https://github.com/wildfly/wildfly-archetypes/blob/main/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/README.txt, last paragraph.

And don't forget the problem the the EAR archetype does not seem to work...

Signed-off-by: Jeff Mesnil <jmesnil@redhat.com>
@jmesnil
Copy link
Member Author

jmesnil commented Aug 31, 2023

@WolfgangHG I'm not able to replicate this issue.

@jmesnil Wait - there is something strange... I cannot create a project from the EAR archetype 30.0.0.Final-SNAPSHOT.

This maven command fails: mvn archetype:generate -DgroupId=foo.bar -DartifactId=multi -Dversion=0.1-SNAPSHOT -Dpackage=foo.bar.multi -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-jakartaee-ear-archetype -DarchetypeVersion=30.0.0.Final-SNAPSHOT -DinteractiveMode=false -DarchetypeCatalog=local -X

Error:

[INFO] Generating project in Batch mode
[DEBUG] Getting archetypes from catalog: C:\Users\USERNAME\.m2\repository\archetype-catalog.xml

Could that be the issue? Your logs have C:\Users\USERNAME for 30.0.0.Final-SNAPSHOT while the previous version displayed:

[DEBUG] Getting archetypes from catalog: C:\Users\knuffi.m2\repository\archetype-catalog.xml

I followed your suggestion and all tests to use the local catalog and the last run looks correct:

[INFO] Archetype repository not defined. Using the one from [org.wildfly.archetype:wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT] found in catalog local
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: wildfly-jakartaee-ear-archetype:30.0.0.Final-SNAPSHOT
[INFO] ----------------------------------------------------------------------------

@WolfgangHG
Copy link
Contributor

@jmesnil About your "C:\Users\USERNAME" comment: I anonymized the paths, but forgot one ;-).

I understand why it did not work for me: I just built the ear archetype, but I did not call "mvn clean install" in the root directory. So, "org.wildfly.archetype:wildfly-archetypes" was not in my local repository.
After having built the root directory, I can create a project from the archetype.

This is the file "wildfly-jakartaee-ear-archetype-29.0.0.Final-SNAPSHOT.pom" in my local repository:

    <parent>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-parent</artifactId>
        <version>39</version>
        <relativePath />
    </parent>

And this "wildfly-jakartaee-ear-archetype-30.0.0.Final-SNAPSHOT.pom", which introduces a new parent dependency that was missing before:

    <parent>
        <groupId>org.wildfly.archetype</groupId>
        <artifactId>wildfly-archetypes</artifactId>
        <version>30.0.0.Final-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

The new file "wildfly-archetypes-30.0.0.Final-SNAPSHOT.pom" file in my local repository contains all the versions and the dependency management that should actually be only contained in the "archetype-resources\pom.xml" file. Isn't this a bunch of unnecessary dependencies, which is not necessary to create the archetype, but

Do we need a parent element at all in the final archetype? Probably it is necessary for building the archetype project, but not when deploying the generated archetype.

@WolfgangHG
Copy link
Contributor

@jmesnil Could you fix the "copy additional files" calls in the batch files of the ear archetype - currently they fail and don't do anything:

Those four lines should be changed to "ejb" instead of "multi-ejb":

copy ..\additionalfiles\TestBean.java .\multi\multi-ejb\src\main\java\foo\bar\multi\

Signed-off-by: Jeff Mesnil <jmesnil@redhat.com>
@jmesnil
Copy link
Member Author

jmesnil commented Sep 1, 2023

@jmesnil Could you fix the "copy additional files" calls in the batch files of the ear archetype - currently they fail and don't do anything:

Sorry, I forgot them. I did not have access to a Windows machine.
Could you please check that they know work fine?
@WolfgangHG I also added the -DarchetypeCatalog=local to them to be consistent with the .sh scripts.

@jmesnil
Copy link
Member Author

jmesnil commented Sep 1, 2023

Do we need a parent element at all in the final archetype? Probably it is necessary for building the archetype project, but not when deploying the generated archetype.

We need it if we want to group all dependencies that are used across the archetypes. This provides a single point of control in the parent pom.xml. By construction, this is a new artefact but this has no impact on the generated Maven project.

The alternative would be to remove the dependency to this parent and have all 3 archetypes define individually the same dependencies (wildfly, failsafe, surefire, etc.).

@WolfgangHG
Copy link
Contributor

Batch files work again, thanks.

I still have a bad feeling about the archetype pom file being cluttered with stuff that is only required at build time, but not for the user of the archetype. But I don't have enough knowledge of maven to give a better suggestion.

Just a bit of brainstorming: would it be possible to create a dummy maven project in this repository that mainly declares the versions and dependencies and is a "catch all" for dependabot. The three archetype projects are again as dumb as before.
When building this "catch all" project, the file "wildfly-jakartaee-ear-archetype\src\main\resources-filtered\archetype-resources\pom.xml" is copied to "wildfly-jakartaee-ear-archetype\src\main\resources\archetype-resources\pom.xml" and then the properties are replaced. Same for war and subsystem archetype.
Seems my suggestion is similar to what you already do with the maven-resources-plugin and the parent pom, but with this suggestion, the archeptype project pom.xml would be as small as before, without a parent pom.
I found https://github.com/floverfelt/find-and-replace-maven-plugin which might help, if the "replaceValue property can be defined as "use value of pom.xml variable".

@jmesnil
Copy link
Member Author

jmesnil commented Sep 4, 2023

would it be possible to create a dummy maven project in this repository that mainly declares the versions and dependencies and is a "catch all" for dependabot

That's the intent of the wildfly-archetypes parent pom.

Seems my suggestion is similar to what you already do with the maven-resources-plugin and the parent pom, but with this suggestion, the archeptype project pom.xml would be as small as before, without a parent pom.

In its current state, the archetypes already have a parent pom (org.jboss:jboss-parent). All this PR does is add a intermediate layer to group the dependencies for the archetypes that are not coming from this jboss-parent.

The key point to me is that this has no impact on the generated Maven project. They will be strictly identical to the one that are generated now. When the user uses the archetype to generate them, they will pull an additional artifact from Maven (the new wildfly-archetypes parent pom) but this is completely transparent to them.

@WolfgangHG
Copy link
Contributor

OK, I see. From my point of view we can accept your pull request ;-)

@jmesnil jmesnil merged commit 97aac8c into wildfly:main Sep 5, 2023
1 check passed
@jmesnil
Copy link
Member Author

jmesnil commented Sep 5, 2023

@WolfgangHG thanks for the thorough review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants