简体   繁体   English

Maven本地存储库未使用最新依赖项更新

[英]Maven local repo not updated with latest dependency

My project has a pom.xml which I did deploy to a remote repository inside my company 我的项目有一个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>

After I do a 'mvn deploy' I did browse the remote repository and I see the project there 在执行“ MVN部署”之后,我确实浏览了远程存储库,并且在那里看到了项目

I have another project that is dependent on the above mentioned 'ProjectMav' and it's POM.xml is as follows 我还有一个依赖于上述“ 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>

Now from eclipse if I do a Maven>update project it does not get the latest version of my 'ProjectMav' to my local repository. 现在从eclipse中,如果我执行Maven> update项目,它不会将“ ProjectMav”的最新版本发送到本地存储库。

But if I clear all the files in my local repo and do a maven update it gets my project 但是,如果我清除本地存储库中的所有文件并进行Maven更新,它将得到我的项目

Any idea what's going on? 知道发生了什么吗?

I believe the issue is that the maven eclipse plugin's update doesn't actually do a mvn install which is what you need if you want to override the 1.0 deployed version. 我认为问题在于,Maven eclipse插件的update实际上并未进行mvn install ,而这是您要覆盖1.0部署版本时需要的。 The way the mvn eclipse plugin orders classpath dependencies (which you can clearly see in the package explorer is to put the dependency jars first and then the resolved upstream projects after the jars). mvn eclipse插件对类路径依赖项进行排序的方式(您可以在软件包资源管理器中清楚地看到,是先将依赖项jar放入,然后将已解决的上游项目放在jar后面)。 This seems to work fine for SNAPSHOT projects as the plugin knows to use your project and not the jars but for release jars it gets confused (or at least I have noticed it to). 对于SNAPSHOT项目,这似乎很好用,因为该插件知道使用您的项目而不是jar,但对于发布jar,它会感到困惑(或者至少我注意到了)。

That being said you should avoid this issue altogether by changing the version of your local one to: 话虽这么说,您应该将本地版本更改为:

<version>1.1-SNAPSHOT</version>

Then in your downstream projects that depend on ProjectMav you update their dependencies to 1.1-SNAPSHOT . 然后,在依赖ProjectMav下游项目中,将其依赖项更新为1.1-SNAPSHOT The management of versions can be tricky so you might want to look into the maven release plugin and have it deal with version-ing of your project when you deploy. 版本管理可能很棘手,因此您可能需要研究maven版本插件,并在部署时让它处理项目的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM