这是一个多模块的maven项目。我已经在我的父母的pom中包含了扁平的maven插件。
<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的版本标记中具有该属性的值。但是,当我给出,mvn安装仍然给出警告,版本应该是常数,但它是一个表达式。
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都会生成以下警告:
警告‘版本’包含一个表达式,但应该是一个常量。
我是不是漏掉了什么东西,不是使用扁平的-pu.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>“属性”用于“大孩子”(用于跟踪,如果在没有警告的情况下成功,我可以在任何地方使用它):
<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
发布于 2014-09-08 10:17:44
我发邮件给这个插件的开发者,他的反应是:
这个警告来自Maven,它基于Maven开始执行之前的原始pom.xml,创建了一个buildplan并分析了pom.xml,导致了这个警告。扁平化的maven插件在稍后的过程中启动,生成扁平的pom.xml,并确保这是正在安装/部署的文件。您的问题不能由扁平Maven插件解决,也不能在Maven Core中修复(警告存在是有充分理由的)。
所以,它很好地回答了这个问题。
https://stackoverflow.com/questions/25682244
复制相似问题