原型应始终使用最新版本的依赖项

Kay*_*ayz 6 maven maven-archetype

我创建了一个原型,它对我的​​一个项目有一个托管依赖.是否有可能告诉原型在使用我的原型创建新项目时始终使用该依赖项的最新版本?使用RELEASE对我不起作用,因为我不想在每次构建项目时更改版本.

    <?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>
Run Code Online (Sandbox Code Playgroud)

我读过这个问题,但是使用maven-versions-plugin建议的解决方案似乎不适合两个原因.首先,我想在创建项目时更改版本,然后我不想更改所有依赖项的版本,只需更改一个版本.

编辑:上面是来自archetype-resources(更新)的pom.xml,下面是我的archetype-project本身的pom.xml.

<?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>
Run Code Online (Sandbox Code Playgroud)

EDIT2: RELEASELATEST似乎无法在管理依赖关系在所有的工作.任何人都可以确认或禁用该声明吗?

Jig*_*shi 1

你可以把

    <dependency>
        <groupId>com.mycompany.myproject</groupId>
        <artifactId>my-artifact</artifactId>
        <version>LATEST</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

LATEST将解析最新的可用版本并-U在构建时通过

或者如果您不想-U每次都指定,您可以配置类似的settings.xml内容~/.m2

<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>
Run Code Online (Sandbox Code Playgroud)

当您运行 mvn 从原型项目生成项目时,您仍然可以指定 LATEST,例如

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
Run Code Online (Sandbox Code Playgroud)