1

I have 2 maven projects where one depends on another. Let's call them common and service.

service specifically depends on a module within common we'll call common-module.

If I make an update to common-module and run mvn clean install, it gets properly installed to my local repository.

Problem

In service, when I do a mvn clean package/install or mvn -U clean package/install will pick up the version that's in the remote repository even though the one I just built is newer. I cannot get it to pick up that latest version even though I see it in my .m2/repository.

How can I get it to pick my locally built jar?

Setup

pom.xml for common (simplified, a lot is excluded)

<?xml version="1.0" encoding="UTF-8"?>  
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"  
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
    <artifactId>common-parent</artifactId>  
    <version>2.4.5-SNAPSHOT</version>  
    <name>Common Parent</name>  
    <modules>  
        <module>common-module</module>  
    </modules>
</project>

pom.xml for common-module (simplified, a lot is excluded)

<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">  
    <artifactId>common-module</artifactId>  
    <name>common-module</name>  
    <description>common-module</description>  
    <parent>  
        <artifactId>common-parent</artifactId>  
        <groupId>com.company.group</groupId>  
        <version>2.4.5-SNAPSHOT</version>  
    </parent>
</project>

pom.xml for service (simplified, a lot is excluded)

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns="http://maven.apache.org/POM/4.0.0"  
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    <artifactId>service</artifactId>  
    <name>service</name>  
    <version>1.2.3-SNAPSHOT</version>
    <dependencies>
        <dependency>  
            <artifactId>common-module</artifactId>  
            <groupId>com.company.group</groupId>  
            <version>2.4.5-SNAPSHOT</version>  
        </dependency>
    </dependencies>
</project>

Note 1: I have a workaround where I can adjust the library settings within IntelliJ and force it to use the correct jar file, but this feels very hacky and unsustainable to me.

Note 2: I've tried changing the <updatePolicy> value in my settings.xml to never and other values, but it seems to have had no effect. This was suggested in other posts I've read before asking here.

            <repository>
                <id>snapshots</id>
                <name>Archiva Managed Snapshot Repository</name>
                <url>http://internal.url/repository/snapshots</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </snapshots>
            </repository>
motopascyyy
  • 79
  • 10
  • This is just for local dev presumably? When I want to be sure I'm only picking up stuff that's local, I just install with a name for the version that will never make it to a real repo, e.g. "michael-1.2.3", and use that in the dependent project. In fact, all our projects use `${revision}` for their version, which is initialized in `` to a default value = `localdev-SNAPSHOT`; CI overrides it to a real version like `1.2.3`. Achieves the same as what I described, but you never have to touch it. – Michael Feb 08 '23 at 21:30
  • Is this a multi module build?? – khmarbaise Feb 09 '23 at 00:02
  • Does this answer your question? [How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts?](https://stackoverflow.com/questions/33548395/how-do-i-force-maven-to-use-my-local-repository-rather-than-going-out-to-remote) – life888888 Feb 09 '23 at 05:05
  • @Micheal, yes it is for local dev only, and yes I could go down that route of a different value for version such as `localdev-SNAPSHOT`. @khmarbaise, yes, multi module but also multi project. I don't have the option of changing that setup unfortunately. @life888888, I tried changing the `updatePolicy` as referenced in that answer, but it seems like it never took effect. My `common-module` that was locally built never got picked up even though it was the newest package (built seconds earlier) – motopascyyy Feb 09 '23 at 17:20
  • If you have a multi module build that has to work otherwise your setup is wrong... That something is tried to get from cache or alike implies something is wrong... Best is to test a multi module setup via the following steps: Try to build on plain command line (outside of IDE): `mvn clean verify -Dmaven.repo.local=$(pwd)/.repo` that should work withou any issue which I doubt... furthermore if you are using `${revision}` in your project version or parents you have to use `flatten-maven-plugin` ...(https://maven.apache.org/maven-ci-friendly.html) – khmarbaise Feb 10 '23 at 16:35

0 Answers0