6

I made an archetype that has a managed dependency to one of my projects. Is there a possibility to tell the archetype to always use the latest release version of that dependency whenever a new project is created with my archetype? Using RELEASE doesn't work for me, since I don't want to change the version everytime the project is built.

    <?xml version="1.0" encoding="utf-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>${groupId}</groupId>
    <artifactId>${artifactId}</artifactId>
    <version>${version}</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>com.mycompany.someproject</groupId>
            <artifactId>someDependency</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.mycompany.myproject</groupId>
                <artifactId>myArtifact</artifactId>

                <version>LATEST</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

I read this question, but the suggested solution with the maven-versions-plugin seems not to be suitable for two reasons. First, I want to change the version when I create the Project and second I don't want to change the versions of all the dependencies but only one.

Edit: above is the pom.xml from archetype-resources (updated), below is the pom.xml from my archetype-project itself.

<?xml version="1.0" encoding="UTF-8"?>

<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>
    <parent>
        <groupId>com.mycompany.maven.archetype.be</groupId>
        <artifactId>maven-archetype-be-_moduleList</artifactId>
        <version>1.3-SNAPSHOT</version>
        <relativePath>../maven-archetype-be</relativePath>
    </parent>
    <artifactId>archetype-be-api</artifactId>
    <packaging>maven-archetype</packaging>
    <dependencies />
    <name>archetype-be-api</name>
</project>

EDIT2: RELEASEand LATEST seem not to work at all in managed dependencies. Can anyone confirm or disable that statement?

Community
  • 1
  • 1
Kayz
  • 637
  • 1
  • 8
  • 21
  • Even if you want to do it for only one dependency, you might want to reconsider it because it might led to some serious problems because of the changes you might not be aware of. But still if you want to do it, you may look at this link it explains your question very well. http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency – SerhatCan Jul 14 '14 at 18:17

1 Answers1

1

You can put

    <dependency>
        <groupId>com.mycompany.myproject</groupId>
        <artifactId>my-artifact</artifactId>
        <version>LATEST</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

LATEST will resolve the latest available version and pass -U when you build

or if you don't want to specify -U each time you can configure your settings.xml in ~/.m2 something like

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>codehausSnapshots</id>
          <name>Codehaus Snapshots</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy> // <-- this will update each release artifact from this repository each time
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <url>http://snapshots.maven.codehaus.org/maven2</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        ...
      </pluginRepositories>
      ...
    </profile>
  </profiles>
  ...
</settings>

when you run the mvn to generate project from your archetype project you can still specify LATEST, for example

mvn archetype:generate 
    -DarchetypeGroupId=you_archetype_group_id 
    -DarchetypeArtifactId=sample-spring-mvc-archetype 
    -DarchetypeVersion=LATEST -DgroupId=new.project.id 
    -DartifactId=sample 
    -DarchetypeRepository=path_to_maven_repo_with_archetype_jar
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Thank you for your response, but that's not what I wanted to do. I'd like to check the latest version, when a project is **created** with my archetype, not everytime it's built. – Kayz Jul 16 '14 at 15:53
  • could you please update your pom.xml of your archetype rpoject – jmj Jul 16 '14 at 16:13
  • so when you run the `mvn` to generate project from your archetype project you can still specify LATEST, for example see the update – jmj Jul 21 '14 at 17:25
  • -DarchetypeVersion=LATEST does not work and will always resolve to the "latest" of the local repository. Propably 0.0.1-SNAPSHOT – Pwnstar Apr 08 '22 at 09:27