简体   繁体   English

Maven发布插件:创建标签,但没有SNAPSHOT依赖性

[英]Maven release plugin: create tag withhout SNAPSHOT depencencies

I am using the Maven release plugin and I am trying to make a release. 我正在使用Maven发布插件,我正在尝试发布。 When I am on master (I am using Git) I have SNAPSHOT versions for both my project (multimodule) and also for my dependencies (also multimodule). 当我在掌握(我正在使用Git)时,我的项目(多模块)和我的依赖项(也是多模块)都有SNAPSHOT版本。

Suppose I want to make a tag from master (skipping the creation of a branch) where no SNAPSHOTs are used. 假设我想从master(跳过创建分支)创建一个标签,其中没有使用SNAPSHOT。

This is my simplified pom.xml: 这是我简化的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>results</artifactId>
<version>1.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Results parent module</name>

<modules>
    <module>results-web</module>
    <module>results-persistence</module>
    <module>results-domain</module>
    <module>results-logic</module>
    <module>results-logic-api</module>
    <module>results-ear</module>
    <module>results-configuration</module>
    <module>results-rules-ejb</module>
    <module>results-rules</module>
    <module>results-rest</module>
</modules>

<properties>
    <dependency1.version>1.2.3-SNAPSHOT</main.version>
    <dependency2.version>3.4.5-SNAPSHOT</main.version>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <tagNameFormat>@{project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <localCheckout>true</localCheckout>
                    <pushChanges>false</pushChanges>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.my.project</groupId>
            <artifactId>dependency1-domain</artifactId>
            <version>${dependency1.version}</version>
        </dependency>
        <dependency>
            <groupId>org.my.project</groupId>
            <artifactId>dependency1-enumerations</artifactId>
            <version>${dependency1.version}</version>
        </dependency>
        <dependency>
            <groupId>org.my.project</groupId>
            <artifactId>dependency1-logic</artifactId>
            <version>${dependency1.version}</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>org.my.project</groupId>
            <artifactId>dependency2-domain</artifactId>
            <version>${dependency2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.my.project</groupId>
            <artifactId>dependency2-enumerations</artifactId>
            <version>${dependency2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.my.project</groupId>
            <artifactId>dependency2-logic</artifactId>
            <version>${dependency2.version}</version>
            <type>ejb</type>
        </dependency>
    </dependencies>
</dependencyManagement>

If I do: 如果我做:

mvn release:prepare -Darguments="-dependency1.version=1.2.3.0 -Ddependency2.version=3.4.5.0" mvn release:prepare -Darguments =“ - dependency1.version = 1.2.3.0 -Ddependency2.version = 3.4.5.0”

That creates a branch that still has SNAPSHOT dependencies: 这会创建一个仍然具有SNAPSHOT依赖关系的分支:

<properties>
    <dependency1.version>1.2.3-SNAPSHOT</main.version>
    <dependency2.version>3.4.5-SNAPSHOT</main.version>
</properties>

How would I generate a tag where the part above would be: 如何生成上面部分的标签:

<properties>
        <dependency1.version>1.2.3.0</main.version>
        <dependency2.version>3.4.5.0</main.version>
</properties>

The release plugin cannot change dependency versions in the POM that are not part of the reactor. 发布插件无法更改POM中不属于reactor的依赖项版本。

Try the Maven Versions Plugin . 试试Maven Versions插件 You can use versions:use-releases to replace all snapshot dependencies with the corresponding releases. 您可以使用版本:use-releases将所有快照依赖项替换为相应的版本。 If you would like to replace them manually (perhaps because the versions differ from the snapshots) you can use versions:set. 如果您想手动替换它们(可能是因为版本与快照不同),您可以使用版本:set。 But both do not work with dependency versions supplied in properties. 但两者都不适用于属性中提供的依赖版本。 For properties versions:update-properties is used with the setting allowSnapshots=false. 对于属性版本:update-properties与allowSnapshots = false设置一起使用。 This goal works automatically if no special version ranges are required but it is configurable to deal with such requirements, too. 如果不需要特殊版本范围,则此目标会自动运行,但也可以配置以处理此类要求。

You can configure the release plugin to call your versions plugin using preparaionGoals as Stephen stated: <preparationGoals>clean versions:use-releases verify</preparationGoals> 您可以使用preparaionGoals配置发布插件来调用您的版本插件,如Stephen所述: <preparationGoals>clean versions:use-releases verify</preparationGoals> prepareGoals <preparationGoals>clean versions:use-releases verify</preparationGoals>

Or you call the versions plugin manually before the release, eg with 或者您在发布之前手动调用版本插件,例如

mvn versions:use-releases scm:checkin -Dmessage="Release versions of dependencies" mvn版本:use-releases scm:checkin -Dmessage =“发布版本的依赖项”

The release plugin is not designed to address this use case. 发布插件不是为解决此用例而设计的。

You might be able to get somewhere by hijacking preparationGoals and completionGoals to call plugins that edit your pom... Certainly that was the use case I had in mind when I added completionGoals 您可能能够通过劫持得到的地方preparationGoalscompletionGoals来调用编辑POM插件......当然,这是使用情况下,我在脑子里,当我加入completionGoals

But for now, in the absence of being able to get a plugin to edit and unedit your pom to set the versions you will have to live with editing by hand 但是现在,由于没有能够获得一个插件进行编辑而且没有你的pom来设置版本,你将不得不忍受手工编辑

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

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