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

archetype contains batch artefacts even when no batch was generated #336

Closed
hohwille opened this issue Jan 26, 2021 · 6 comments · Fixed by #394
Closed

archetype contains batch artefacts even when no batch was generated #336

hohwille opened this issue Jan 26, 2021 · 6 comments · Fixed by #394
Labels
bug Something isn't working

Comments

@hohwille
Copy link
Member

hohwille commented Jan 26, 2021

Expected behavior

As a user of devon4j, I want to create a new app with minimal content so that I am not spammed with unneccessary pointless classes that I have to delete.

Actual behavior

Even though I did not choose to generate my app with batch I got the following files (starting from the root of the create app and NOT in batch subfolder/module):

  • ./src/main/resources/db/migration/h2/V0005__Add_batch_tables.sql
  • ./src/main/java/org/example/app/SpringBootBatchApp.java
  • ./src/main/java/org/example/app/general/batch/impl/config/BeansBatchConfig.java
  • ./src/test/java/org/example/app/general/batch/base/test/SpringBatchIntegrationTest.java
  • ./src/test/java/org/example/app/general/common/base/test/TestUtil.java

This looks like something is messed in the archetype to me.

Steps to reproduce (bug) / Use Case of feature request (enhancement)

  1. devon java create org.example.app
  2. cd app
  3. find src

Affected version:

Latest devon4j version 2020.12.001.

Documentation notice:

Together with this story also the EAR support to generate an ear module has been removed as it is entirely obsolete and more considered as anti-pattern that should not be explicitly supported.

@hohwille hohwille added the bug Something isn't working label Jan 26, 2021
@hohwille
Copy link
Member Author

The sources are located in a __batch__ folder:

https://github.com/devonfw/devon4j/blob/466368dbeb229a27f53c1f3ad1dd93fd2f5df418/templates/server/src/main/resources/archetype-resources/__batch__/src/main/java/__packageInPathFormat__/SpringBootBatchApp.java

Maybe this bug has been there from the start and nobody noticed or reported this before. This "optional additions" for the maven archetype are kind of odd.

@hohwille
Copy link
Member Author

<validationRegex>batch|[.]</validationRegex>

IMHO this means that __batch__ is just a placeholder that can be replaced with batch to get the batch as regular module/folder and by default it is replaced with . what means that the content below __batch__ is added to the toplevel project. This is how it has ever been and it was wrong all the time.
It seems that maven archetypes are just hacks and allowing optional modules in an archetype can not be archived this way cleanly...

@hohwille
Copy link
Member Author

hohwille commented Jan 26, 2021

https://stackoverflow.com/questions/34735040/can-a-multi-module-maven-archetype-be-set-up-to-have-optional-modules

You may be able to workaround this using partial archetypes by setting partial="true" in the descriptor, which allows the generation of a project on top of an existing project. This post seems to tackle the same issue.

That sounds much more reasonable: We could have our simple standard archetype as is without batch, ear, and other clutter. Then we could have an additional partial archetype for batch that afterwards can be "added" as "additional opt-in feature"?
Besides I would drop the ear support when we address this issue as EARs are pretty much a JEE dead-end nightmare that we consider as anti-pattern so we should not put any further effort into such nonsense...

@tobka777
Copy link
Member

tobka777 commented May 5, 2021

I will have a look at it and hopefully find a good solution. But the approach with partial and a basic variant of the template appealed to me. And I would drop ear support.

tobka777 added a commit to tobka777/devon4j that referenced this issue May 19, 2021
tobka777 added a commit to tobka777/devon4j that referenced this issue May 19, 2021
@tobka777
Copy link
Member

Ok now I found a good solution without partial and it works ;).

First you execute: mvn -DarchetypeVersion="2021.04.002-SNAPSHOT" -DarchetypeGroupId="com.devonfw.java.templates" -DarchetypeArtifactId=devon4j-template-server archetype:generate -DgroupId="com.example.application" -DartifactId=sampleapp -Dversion="1.0.0-SNAPSHOT" -Dpackage="com.devonfw.application.sampleapp" -Dbatch=batch
You have to add -Dbatch=batch because there is a dependency in server/pom.xml.

Then you go in the folder sampleapp and execute: mvn -DarchetypeVersion="2021.04.002-SNAPSHOT" -DarchetypeGroupId="com.devonfw.java.templates" -DarchetypeArtifactId=devon4j-template-batch archetype:generate -DgroupId="com.example.application" -DartifactId=batch -Dversion="1.0.0-SNAPSHOT" -Dpackage="com.devonfw.application.sampleapp" -DparentArtifactId=sampleapp
That add the batch folder and add the module to pom.xml. I added a property parentArtifactId to replace the marker in batch/pom.xml correctly. artifactId does not work because this is the module and folder name. I need the parent ArtifactId in the pom.xml.

The pom.xml has many empty lines which is related to this issue. Maybe we should remove empty lines.
https://issues.apache.org/jira/browse/ARCHETYPE-584

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