使用来自外部依赖项的过滤器文件过滤Maven资源 [英] Filter maven resources with filter-file from external dependency

查看:111
本文介绍了使用来自外部依赖项的过滤器文件过滤Maven资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在maven项目A中提供属性文件

Given a property file in maven project A

我想在项目B中使用它们进行资源过滤.

I want to use them in project B for resource filtering.

所以在项目B中,我使用

So in Project B I use

<build>
        <filters>
            <filter>${project.build.directory}/myFile.properties</filter>
        </filters>
 </build>

根据myFile.properties中的值过滤我的资源此文件存储在项目A中.因此我将其包含在

To filter my resources based on values in myFile.properties This file is stored in project A. So I include it with

    <build>
  <plugins>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>groupa</groupId>
                                <artifactId>a</artifactId>
                                <version>${project.version}</version>
                                <type>test-jar</type>
                                <outputDirectory>${project.build.directory}</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

问题是资源过滤发生在复制依赖项之前.因此,在将myFile.properties手动复制到$ {project.build.directory}时,过滤确实起作用,但不适用于mvn clean ...

Problem is that the resource filtering happens before the dependency is copied. So filtering does work when copying myFile.properties manually to ${project.build.directory} but it does not work with a mvn clean ...

如何在实际过滤发生之前复制filterFile?

How can I copy the filterFile before the actual filtering happens?

推荐答案

Maven插件按照它们在pom中出现的顺序执行. AFAIK在父项(和超级pom)中配置的插件先于pom的插件执行.

Maven plugins are executed in the order they appear in the pom. AFAIK the plugins configured in the parent (and the super pom) are executed before the plugins of the pom.

我的建议是在依赖插件之后显式声明资源插件:

My suggestion is declaring the resources plugin explicitely after the dependency plugin:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <!-- ... -->
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-resources-plugin</artifactId>
      <!-- ... -->
    </plugin>
  </plugins>
</build>

这篇关于使用来自外部依赖项的过滤器文件过滤Maven资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆