How can I make resources like .gitignore be part of the resulting project?
archetype-resources/.gitignore
mvn installmvn archetype:generate.gitignore
PS. I'm sure it isn't there.
The Archetype Plugin allows the user to create a Maven project from an existing template called an archetype. It also allows the user to create an archetype from an existing project. This plugin requires Java 7.
the archetype should now be listed in ~/. m2/archetype-catalog. xml or /path/to/local/mvn/repo/archetype-catalog. xml.
In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The name fits as we are trying to provide a system that provides a consistent means of generating Maven projects.
The bug seems to be still present in the maven-archetype-plugin v3.0.1 . For those who do not want to downgrade the maven-resource-plugin. I managed to establish a more or less ugly workaround.
First you rename the archetype-resources/.gitignore to
__gitignore__
then inside the archetype-metadata.xml add
<requiredProperties>
<requiredProperty key="gitignore">
<defaultValue>.gitignore</defaultValue>
</requiredProperty>
</requiredProperties>
<fileSets>
<fileSet>
<directory></directory>
<includes>
<include>__gitignore__</include>
</includes>
</fileSet>
</fileSets>
When the archetype is generated maven will now first copy the __gitignore__ then sees the __[file]__ syntax and will replace it with the default value ".gitignore"
This solution for upcoming maven-resources-plugin v3.0.0 (not yet released at the time of posting this; current is still 2.7) from https://issues.apache.org/jira/browse/MRESOURCES-190 seems better than holding back version upgrades:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<!-- Required so that .gitignore gets included in archetypes; see https://issues.apache.org/jira/browse/MRESOURCES-190 -->
<addDefaultExcludes>false</addDefaultExcludes>
Add a fileSet entry to src/main/resources/META-INF/maven/archetype-metadata.xml with an empty directory tag:
<fileSet>
<directory></directory>
<includes>
<include>.gitignore</include>
</includes>
</fileSet>
This will copy the included files from src/main/resources/archetype-resources to the project root directory.
Check your maven-resources-plugin version by launching the Maven build on debug (with -X option). If you use 2.7, there is a regression where .gitignore files are silently ignored.
In this case, you will have to explicitly use 2.6 in your pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</pluginManagement>
</build>
ARCHETYPE/issues/ARCHETYPE-505 shows that this is thoroughly broken with current versions of the plugin and maven. No workarounds help anymore with this.
Solution that worked perfectly for me was to use archetype post install groovy script.
Create a file META-INF/archetype-post-generate.groovy in the resources folder of your archetype project.
Add this code:
file = new File( request.getOutputDirectory(), request.getArtifactId()+"/.gitignore.tmpl" );
def gitIgnorefile = new File( request.getOutputDirectory(), request.getArtifactId()+"/.gitignore" );
file.renameTo(gitIgnorefile)
In your archetype-metadata.xml file include the template .gitignore.tmpl file.
<fileSet>
<directory/>
<includes>
<include>.gitignore.tmpl</include>
</includes>
</fileSet>
I had problems with maven resource plugin hence used groovy script solution.
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