Maven archetype plugin doesn't let .resources in archetype-resources through

偶尔善良 提交于 2019-12-21 03:13:38

问题


Does anybody know how can I make resources like .gitignore be part of the resulting project ?

  1. create archetype with archetype-resources/.gitignore
  2. mvn install
  3. mvn archatype:generate
  4. resulting project doesn't contain .gitignore

PS. I'm sure it isn't there.


回答1:


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>



回答2:


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.




回答3:


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"




回答4:


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>



回答5:


Alternative for downgrading maven-resources-plugin is to enforce plexus-utils version which actually has a regression:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.7</version>
    <dependencies>
        <!-- it's for fixing maven-resources-plugin 2.7 MRESOURCES-190 -->
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <!-- this is last 2.x release -->
            <version>2.1</version>
        </dependency>
    </dependencies>
</plugin>



回答6:


the bug is still in the newest maven-archetype-plugin 2.4 and maven-resources-plugin 3.0.1.

here is the solution:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-archetype-plugin</artifactId>
    <version>2.2</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
 </plugin>

and in your generate pom.xml you should add

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
 </plugin>


来源:https://stackoverflow.com/questions/7981060/maven-archetype-plugin-doesnt-let-resources-in-archetype-resources-through

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!