Filter maven resources with filter-file from external dependency

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:14:03

问题


Given a property file in maven project A

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

So in Project B I use

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

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>

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 ...

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


回答1:


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>


来源:https://stackoverflow.com/questions/28047152/filter-maven-resources-with-filter-file-from-external-dependency

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