通过Java注释处理器生成的Maven过滤资源

时间:2018-05-03 13:28:16

标签: java maven

我有一个注释处理器,它生成一个文本文件,包含在编译的jar中。 (注释处理器位于正在编译的同一项目中。)

生成的文件中有一个${project.version}字符串,我希望将其替换为典型的maven资源过滤。

我如何实现这一目标?

我当前的pom.xml的构建部分是

<build>
    <finalName>prodity-commons-spigot</finalName>
    <sourceDirectory>src/main/java</sourceDirectory>

    <resources>
        <resource>
            <directory>${project.basedir}/src/main/resources/META-INF</directory>
            <targetPath>./META-INF</targetPath>
            <filtering>false</filtering>
            <includes>
                <include>services/javax.annotation.processing.Processor</include>
            </includes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <id>default-compile</id>
                    <configuration>
                        <compilerArgument>-proc:none</compilerArgument>
                    </configuration>
                </execution>
                <execution>
                    <id>compile-project</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:0)

过滤必须为true:

<resources>
        <resource>
            <directory>${project.basedir}/src/main/resources/META-INF</directory>
            <targetPath>./META-INF</targetPath>
            <filtering>true</filtering>
            <includes>
                <include>services/javax.annotation.processing.Processor</include>
            </includes>
        </resource>
    </resources>