【问题标题】:How to copy file from Parent POM into Maven Project如何将文件从父 POM 复制到 Maven 项目中
【发布时间】:2018-03-23 16:22:42
【问题描述】:

我想要一个包含两个文件的父 Maven 项目。

src/license/LICENSE.txt src/license/NOTICE.txt

当我构建我的主项目时,将其作为父 POM 引用,我希望将这些文件包含在生成的 JAR 中。

我知道我可以使用...

<build>
    <resources>
        <resource>
            <targetPath>META-INF</targetPath>
            <directory>src/license</directory>
            <includes>
                <include>NOTICE.txt</include>
                <include>LICENSE.txt</include>
            </includes>
        </resource>
    </resources>    
</build>

但这仅在文件位于主项目中时有效,而不是在它们位于父项目中时。

【问题讨论】:

标签: maven maven-3


【解决方案1】:

我找到了解决办法。

首先,创建一个新的存储库来保存您要复制的项目。

这个的 POM 应该包含这个(GAV 细节是 com.jeff:base-pom-license)...

<build>
    <plugins>
        <plugin>
            <artifactId>maven-remote-resources-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>**/*.txt</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

然后在你的 Base pom 中添加这个...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-remote-resources-plugin</artifactId>
            <version>1.5</version>
            <configuration>
                <resourceBundles>
                    <resourceBundle>com.jeff:base-pom-license:${project.version}</resourceBundle>
                </resourceBundles>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>       

这将导致您在新的 maven 存储库中拥有的文件包含在扩展基础 pom 的所有位置中。

【讨论】:

  • 这似乎是一个有用的解决方案(类似于我的建议),但它不会从父项目中读取文件。
猜你喜欢
  • 2011-05-09
  • 2021-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多