[英]Maven flatten plugin not working does not substitute my version property
For some reason when i do mvn install and check my local repo and look at the pom there, i don't see that the version variable was substituted with the value.出于某种原因,当我执行 mvn install 并检查我的本地 repo 并查看那里的 pom 时,我没有看到 version 变量被替换为值。
I am using a parent pom with a version in the properties我在属性中使用带有版本的父pom
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<revision>19.3.29</revision>
</properties>
It also contains the flatten plugin entry:它还包含 flatten 插件条目:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
The child pom uses the ${revision} as the value for the version & ${project.version} for dependencies as recommended by maven:子pom 使用 ${revision} 作为版本值和 ${project.version} 作为 maven推荐的依赖项的值:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>analysisModule</artifactId>
<version>${revision}</version>
<parent>
<groupId>com.mycompany.analysis</groupId>
<version>1.0.0</version>
<artifactId>autoav</artifactId>
<relativePath>../autoAV</relativePath>
</parent>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.mycompany.analysis</groupId>
<artifactId>analysisCore</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Looking at the local repo pom xml after I 'mvn install':在我“mvn install”之后查看本地 repo pom xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>analysisJdbc</artifactId>
<version>${revision}</version>
<description>analysis of jdbc sources</description>
<parent>
<groupId>com.mycompany.analysis</groupId>
<version>1.0.0</version>
<artifactId>autoav</artifactId>
<relativePath>../autoAV</relativePath>
</parent>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.mycompany.analysis</groupId>
<artifactId>analysisCore</artifactId>
<version>${project.version}</version>
</dependency>
...
</project>
Shouldn't the ${revision} & ${project.version} been replaced with the actual numbers? ${revision}和${project.version}不应该替换为实际数字吗? Isn't that the whole thing about using flatten plugin?
这不是使用 flatten 插件的全部内容吗?
I followed this https://www.mojohaus.org/flatten-maven-plugin/examples/example-central-version.html我跟着这个https://www.mojohaus.org/flatten-maven-plugin/examples/example-central-version.html
Adding my output of mvn install (skipping tests) (maven version 3.3.9):添加我的 mvn install 的 output (跳过测试)(maven 版本 3.3.9):
02:12:03 :/code/thedrs/gitrepos/analysis/analysis/analysisJdbc (main) $ mvn install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building analysisJdbc 19.3.30
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ analysisJdbc ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ analysisJdbc ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ analysisJdbc ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ analysisJdbc ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ analysisJdbc ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ analysisJdbc ---
[INFO] Building jar: /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/target/analysisJdbc-19.3.30.jar
[INFO] META-INF/maven/com.mycompany.analysis/analysisJdbc/pom.xml already added, skipping
[INFO] META-INF/maven/com.mycompany.analysis/analysisJdbc/pom.properties already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ analysisJdbc ---
[INFO] Installing /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/target/analysisJdbc-19.3.30.jar to /code/thedrs/.m2/com/mycompany/analysis/analysisJdbc/19.3.30/analysisJdbc-19.3.30.jar
[INFO] Installing /code/thedrs/gitrepos/analysis/analysis/analysisJdbc/pom.xml to /code/thedrs/.m2/com/mycompany/analysis/analysisJdbc/19.3.30/analysisJdbc-19.3.30.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.147 s
[INFO] Finished at: 2020-05-06T02:12:40-07:00
[INFO] Final Memory: 14M/356M
[INFO] ------------------------------------------------------------------------
You need to move the plugin from <pluginManagement><plugins>
to <plugins>
.您需要将插件从
<pluginManagement><plugins>
移动到<plugins>
。 Alternatively, you can leave it there and just add a short plugin definition (including groupId and artifactId) to the <plugins>
section.或者,您可以将其保留在那里,只需将一个简短的插件定义(包括 groupId 和 artifactId)添加到
<plugins>
部分。
<pluginManagement>
is just to preconfigure version numbers and configuration. <pluginManagement>
只是为了预配置版本号和配置。 Plugins in <pluginManagement>
are not run during the build unless they reappear in <plugins>
. <pluginManagement>
中的插件在构建期间不会运行,除非它们重新出现在<plugins>
中。
I've been able to achieve that by creating another property for the dependencies.我已经能够通过为依赖项创建另一个属性来实现这一点。 This property will have the same value as
${revision}
and will be replaced in the generated pom file.此属性将具有与
${revision}
相同的值,并将在生成的 pom 文件中替换。
<properties>
<revision>19.3.29</revision>
<my-lib.version>${revision}</my-lib.version>
</properties>
Then instead of using ${project.version}
in your dependencies, use your property:然后,不要在依赖项中使用
${project.version}
,而是使用您的属性:
<dependency>
<groupId>com.mycompany.analysis</groupId>
<artifactId>analysisCore</artifactId>
<version>${my-lib.version}</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.