这是一个多模块的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
它会生成一个警告: [警告]&#39;版本&#39;包含表达式但应该是常量。
在所有模块中创建扁平的pom,包括父级和所有子级。
展平的pom具有子pom的 版本 标记中的属性值。但是当我给出时,mvn install它仍会发出警告,即版本应该是常量但是它是一个表达式。
http://mojo.codehaus.org/flatten-maven-plugin/plugin-info.html
但是文件说:
这个MOJO意识到生成扁平POM的目标变平 并可能更新POM文件以便当前 MavenProject的文件指向扁平的POM而不是 原始的pom.xml文件。扁平的POM是缩小版的 原始POM的重点只包含重要信息 消费它。因此,只需要的信息 开发人员的维护和构建项目工件 剥离
所以当我做mvn安装时,它不应该生成警告。
mvn install和mvn flatten:flatten both都会生成此警告:
[警告]&#39;版本&#39;包含表达式但应该是常量。
我错过了什么,是不是使用flattened-pom.xml。 我是否需要指定一些内容。
父母:
<?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>
除此之外,它还有bundle plugin依赖插件和一些依赖项。在这个孩子的扁平pom中,这个版本被解析为0.0.1
答案 0 :(得分:7)
我邮寄给这个插件的开发者,他的回答是:
警告来自Maven,基于原始 pom.xml 在Maven开始执行之前,会创建一个构建计划和pom.xml 分析,导致此警告。 flatten-maven插件开始了 稍后在生成扁平pom.xml的过程中并确保 这是正在安装/部署的文件。您的问题无法解决 flatten-maven-plugin并没有在Maven Core中修复(警告 是有充分理由的。)
所以,它很好地回答了这个问题。