Maven archetype plugin doesn't let .resources

2019-03-23 01:52发布

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.

6条回答
放荡不羁爱自由
2楼-- · 2019-03-23 01:59

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>
查看更多
别忘想泡老子
3楼-- · 2019-03-23 02:09

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.

查看更多
Emotional °昔
4楼-- · 2019-03-23 02:10

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>
查看更多
ら.Afraid
5楼-- · 2019-03-23 02:13

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楼-- · 2019-03-23 02:15

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"

查看更多
放我归山
7楼-- · 2019-03-23 02:17

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>
查看更多
登录 后发表回答