【发布时间】:2014-10-30 04:37:32
【问题描述】:
这是一个多模块的maven项目。我在我的父 pom 中包含了 flatten-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0-beta-2</version>
<configuration>
</configuration>
在父 pom 中定义了一个属性 scl_version 并在子 pom 中使用了 ${scl_version}。值为 0.0.1。
当我运行 mvn flatten:flatten
它会产生一个警告: [警告] 'version' 包含一个表达式,但应该是一个常量。
在所有模块中创建一个扁平化的 pom,包括父模块和所有子模块。
扁平化 pom 具有子 pom 的 version 标签中的属性值。但是当我给出时, mvn install 它仍然会警告版本应该是恒定的,但它是一个表达式。
http://mojo.codehaus.org/flatten-maven-plugin/plugin-info.html
但是文档说:
这个 MOJO 实现了生成扁平化 POM 的目标 flatten 并可能更新 POM 文件,以便当前 MavenProject 的文件指向扁平化的 POM 而不是 原始 pom.xml 文件。扁平化 POM 是 原始POM,重点仅包含重要信息 消费它。因此,仅需要的信息 由开发人员维护和构建项目工件是 剥离。
所以当我执行 mvn install 时,它不应该产生警告。
mvn install 和 mvn flatten:flatten 都会产生这个警告:
[WARNING] 'version' 包含一个表达式,但应该是一个常量。
我错过了什么,是不是使用 flattened-pom.xml。 我需要指定什么吗?
父 POM:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<modules>
<module>Resources</module>
<module>ResourceTree</module>
<module>Service</module>
<module>Transport</module>
<module>Branding</module>
属性标签从这里开始
<scl_version>0.0.1</scl_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<karaf.deploy.build.folder>${env.KARAF_BASE}/deploy</karaf.deploy.build.folder>
属性标签到此结束
<profiles>
<profile>
<id>code_coverage</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0-beta-2</version>
<configuration>
<flattenMode>ossrh</flattenMode>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>0.7.0.201403182114</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
生成的扁平化 pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
</project>
属性用于大孙子 pom(用于跟踪,如果成功而没有警告,我可以在任何地方使用它):
<groupId>org.a.b</groupId>
<artifactId>CD<artifactId>
<version>${scl_version}</version>
<packaging>bundle</packaging>
<name>CD</name>
<description>OSGi bundle project.</description>
除此之外,它还有捆绑插件依赖插件和一些依赖项。在这个孩子的扁平化 pom 中,这个版本被解析为 0.0.1
【问题讨论】:
-
你能显示你的 pom 文件吗?因为否则很难理解问题可能是什么。
标签: java maven-2 maven-3 pom.xml