Is there a way to run mvn archetype:generate and target the current directory instead of creating a directory from the artifactId? The plugin supposedly takes a basedir parameter, but passing in "-Dbasedir=." doesn't do the trick.
For additional context, I've got 2 Git repositories setup. The first contains the source of a Maven archetype for generating custom web services, and the second is a sample service generated from the archetype. I've got a Jenkins job that builds my archetype by essentially just running "mvn clean install". I'm trying to setup a second Jenkins job as part of our CI workflow generates a test service using "mvn archetype:generate", builds the service with mvn clean install, spins up the service, runs some integration tests, and then pushes the source for the test service into a second repository if the tests pass. Both Jenkins jobs use the Maven 2/3 build job type, and I've specified our Git repo information in the SCM section of the job configuration, so the jobs start by doing a "git clone".
For the second job, my current workflow looks like this:
// Clean out the existing source and commit locally.
git rm -r .
git commit -m "Cleaning out previous version." .
// Generate the new source from the archetype.
mvn archetype:generate ...
// Big hack that I'd like to remove.
mv <artifactId>/* .
rm -rf <artifactId>
// Add the new generated source and commit locally.
git add -A .
git commit -m "Committing new version." .
// Build and test.
mvn integration-test
// Assuming that passed, commit the changes.
git push origin master
The hack is there because I'm not sure how to tell the archetype plugin to use my current directory instead of creating a nested directory with the name of the artifactId, so I have to move everything back into my local repository root directory and delete the directory that was created. Not the end of the world, but it feels ugly. Note that I'm open to suggestions on how to better accomplish my overall goal in addition to answers to my initial question. :) Thanks in advance!
Sponsoring Apache Thanks Follow ASFMavenProject archetype:generate Full name: org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate Description: Generates a new project from an archetype, or updates the actual project if using a partial archetype.
To create a new project based on an Archetype, you need to call mvn archetype:generate goal, like the following: Please refer to Archetype Plugin page. Maven provides several Archetype artifacts: An archetype to generate a sample archetype project.
To create a new application project or smart library project, use the Maven archetypes (simple archetype or lib archetype) with the BMC Helix Platform SDK. For your projects, decide where you want your project code to reside.
The maven-archetype-plugin allows the user to create a Maven project through the generate goal and existing archetype. For more information on this plugin, you can visit the homepage.
It is not possible without some kind of workaround, because of 2 reasons:
The basedir
property doesn't work, see this issue.
The archetype plugin always adds artifactId as the last child directory. You can see this in the sources.
Your options
keep your hack, it is not so horrible ;-)
is it important that the project is in the root of the repository? if not just do cd <artifactId>
before the build/integration tests
if building from root of the repository is required then use root pom.xml of type pom, with the generated project as child module (I think this is what other post suggests as #3)
provide a PR to add desired functionality to maven archetype plugin, this might take some time, but is probably the cleanest solution
I know it's old topic but I had similar issue:
The archetype:generate goal has a parameter outputDirectory, you can set it to root folder (../). When generating artifact from archetype it's important that your artifact name is same as current directory.
mvn archetype:generate -DarchetypeGroupId=[archetype-group] -DarchetypeArtifactId=[archetype-id] -DoutputDirectory=../ -DartifactId=[current-folder-name] -DgroupId=[whatever-you-want] -Dversion=[ex: 0.1] -Dpackage=[jar|pom|etc.] -B
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With