【问题标题】:Maven local repo not updated with latest dependencyMaven 本地存储库未使用最新依赖项更新
【发布时间】:2014-12-04 19:42:13
【问题描述】:

我的项目有一个 pom.xml,我确实将它部署到了我公司内部的远程存储库

<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>ProjectMav</groupId>
<artifactId>ProjectMav</artifactId>
<version>1.0</version>
<distributionManagement>
    <repository>
        <id>man-release</id>
        <name>mav release repo</name>
        <url>http://xxxxxx.net/repositories/mav-release/</url>
    </repository>
    <snapshotRepository>
        <id>mav-snapshots</id>
        <name>mav snapshots repo</name>
        <url>http://xxxxxx.net/repositories/mav-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

执行“mvn deploy”后,我确实浏览了远程存储库,并且在那里看到了项目

我有另一个项目依赖于上面提到的“ProjectMav”,它的 POM.xml 如下

<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>mavtest</groupId>
<artifactId>mavtest-suite</artifactId>
<version>1.0</version>
<dependencies>
    <dependency>
        <groupId>ProjectMav</groupId>
        <artifactId>ProjectMav</artifactId>
        <version>1.0</version>
        <scope>compile</scope>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>mav-release</id>
        <name>mav release repo</name>
        <url>http://xxxxxx.net/repositories/mav-release/</url>
    </repository>
</repositories>
<build>
    <testSourceDirectory>src/com/mav/</testSourceDirectory>
    <resources>
        <resource>
            <directory>/resources</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

现在,如果我执行 Maven>更新项目,它不会从 Eclipse 获取我的“ProjectMav”的最新版本到我的本地存储库。

但如果我清除本地 repo 中的所有文件并进行 maven 更新,它会得到我的项目

知道发生了什么吗?

【问题讨论】:

    标签: eclipse maven maven-2 maven-3 maven-plugin


    【解决方案1】:

    我认为问题在于 maven eclipse 插件的 update 实际上并没有执行 mvn install 如果您想覆盖 1.0 部署的版本,这是您所需要的。 mvn eclipse 插件排序类路径依赖的方式(你可以在package explorer中清楚地看到是先放置依赖jars,然后将解析的上游项目放在jars 之后)。这似乎适用于 SNAPSHOT 项目,因为插件知道使用您的项目而不是 jar,但对于发布 jar,它会感到困惑(或者至少我已经注意到它)。

    话虽如此,您应该通过将本地版本更改为:

    <version>1.1-SNAPSHOT</version>
    

    然后在依赖ProjectMav 的下游项目中,将它们的依赖关系更新为1.1-SNAPSHOT。版本管理可能很棘手,因此您可能需要查看 maven 发布插件,并在部署时让它处理您的项目的版本。

    【讨论】:

    • 我尝试将我的 ProjectMav 的 pom.xml 版本更改为 1.1-SNAPSHOT 并将下游项目之一更新为 2.1-SNAPSHOT 依赖项。即使通过 eclipse 更新项目也不会将 ProjectMav 的最新快照下载到我的本地存储库。
    • 它不会出现在您的 maven 存储库(即 ~/.m2)中,因为 eclipse 插件现在依赖于 eclipse 项目本身的代码,而不是本地安装的工件。如果您想在本地 repo 中查看项目和/或使用命令行,您需要在项目上运行 mvn install
    • 知道了。非常感谢。
    猜你喜欢
    • 2014-03-27
    • 2020-07-13
    • 2015-11-13
    • 2011-02-10
    • 2019-12-31
    • 2016-11-13
    • 2014-03-01
    • 1970-01-01
    相关资源
    最近更新 更多