在Maven中,依赖项通常设置如下:
<dependency>
<groupId>wonderful-inc</groupId>
<artifactId>dream-library</artifactId>
<version>1.2.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
现在,如果您正在使用频繁发布的库,不断更新<version>标记可能有些烦人.有没有办法告诉Maven始终使用最新的可用版本(来自存储库)?
在maven多模块项目中,我希望每个模块始终保持与父模块相同的版本,我通常在模块的pom.xml中执行以下操作:
<parent>
<groupId>com.groupId</groupId>
<artifactId>parentArtifactId</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<groupId>com.groupId</groupId>
<artifactId>artifactId</artifactId>
<packaging>jar</packaging>
<version>${project.parent.version}</version>
<name>name</name>
Run Code Online (Sandbox Code Playgroud)
自从我开始使用maven 3.0-alpha-5以来,我收到了以下警告.
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.groupid.artifactId:name:jar:1.1-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ com.groupid.artifactId:name::${project.parent.version}, /Users/whaley/path/to/project/child/pom.xml
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Run Code Online (Sandbox Code Playgroud)
我很想知道将模块的版本绑定到父版本的真正问题是,如果有的话?或者这是一个一般警告的情况,当任何表达式,无论是否是project.parent.version,用于版本元素.
我有几个由maven构建的项目,我想在它们之间共享一些常见的属性 - spring版本,mysql驱动程序版本,svn base url等等 - 所以我可以更新它们一次,它将反映在所有项目中.
我想过有一个带有所有属性的超级pom,但如果我改变其中一个问题,我需要增加它的版本(并更新所有poms继承它)或从所有开发人员的机器中删除它我不想这样做.
可以在pom外部指定这些参数吗?我仍然希望在父pom中具有外部位置定义.
http://maven.apache.org/pom.html#Properties表示属性"值可在POM内的任何位置访问".
这应该是" 在POM内的大多数地方都可以访问"吗?
我可以指定依赖的版本没有问题,如下所示:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是项目本身的版本如何:
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>${myversion}</version>
<properties>
<myversion>8</myversion>
</properties>
<modules>
<module>alpha</module>
<module>beta</module>
</modules>
...
Run Code Online (Sandbox Code Playgroud)
如果我尝试这个<version>将不会取值8.这里我在pom中定义了$ {myversion}但是如果我在命令行中指定-Dmyversion = 8,情况似乎也是如此.
如果其中一个模块使用硬编码版本号指定其父级,如下所示:
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>8</version>
</parent>
Run Code Online (Sandbox Code Playgroud)
当我尝试构建然后当maven来看模块的pom时,它会说它无法找到版本8的给定父pom.
但是,如果我将父版本中的版本硬编码为8,而不是使用$ {myversion},那么一切正常.
所以在我看来,父pom的/ project/version标签不会发生属性替换.
是这种情况还是对我似乎看到的内容有其他解释?
问候,
/乔治
maven-2 ×3
maven ×2
dependencies ×1
java ×1
maven-3 ×1
pom.xml ×1
properties ×1
substitution ×1