项目结构:
packagetest:顶级父级
c1:子项目(web项目)
c2:子项目(jar包)
c1依赖c2的jar包。
在父级maven中deploy成功,package也成功,私服上有都有包了。但是在c1上package的时候,报错提示:
Failed to execute goal on project c1: Could not resolve dependencies for project com.example:c1:jar:1.0.0-SNAPSHOT: Failed to collect dependencies at com.example:c2:jar:1.0.0-SNAPSHOT: Failed to read artifact descriptor for com.example:c2:jar:1.0.0-SNAPSHOT: Failure to find com.example:packagetest:pom:${reversion} in http://xxxx/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus-repo has elapsed or updates are forced -> [Help 1]
也就是说com.example:packagetest:pom:${reversion} 中的这个${reversion}没有变成对应“1.0.0-SNAPSHOT”。
我猜测,在c1下打包,因为parent的pom的version是变量,所以maven没有办法在c1的上级目录找到完全匹配的pom,所以尝试从local repository中查找,在repository中尝试查找version为${reversion}的pom,显然也是找不到的。
模块的的父项目version可以直接配置成1.0.0-SNAPSHOT,如果怕修改麻烦的话,推荐:
1,idea插件maven project version,一键修改所有子模块的parent version
2,mvn --batch-mode release:update-versions -DdevelopmentVersion=1.0.0-SNAPSHOT
下面是官方对于relativePath的解释:
The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent POM. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project. Set the value to an empty string in case you want to disable the feature and always resolve the parent POM from the repositories.
Default value is: ../pom.xml.
${reversion} 这个属性看来解析不了啊,
可以用在 项目的<version>节点里面吗?
一般是在 <dependency>节点里面使用的。
暂时无法解决。
报错这个com.example:c2:jar:1.0.0-SNAPSHOT说明maven已经是找到了版本
估计和使用了SNAPSHOT有关,使用私服是SNAPSHOT这种是需要特别设置的
可以换版本号试试,如1.1.0,而不使用1.0.0-SNAPSHOT
还有一种情况,.m2下的文件记录错误,将这个对应的目录删除下,重试