Maven release plugin tag, publish release version to nexus

1. Background

 SNAPSHOT is the snapshot version, which is not stable and is the version used during development. When the test is stable, the RELEASE version can be released

The following describes the experimental environment:

Maven 3.3.1

nexus 2.11.1

Subversion 1.8.x

Note: SVN Connector and Subversion (mainly because the BIN directory contains some SVN client command programs) versions must be consistent

Eclipse Mar (currently found SVN icons, such as unsynchronized icons, etc., I don't know why they can't be displayed, I don't care about this)

 

2. Steps

2.1 Create a new Maven project

 

     How to build it will not explain too much, I believe everyone already knows this

 

2.2 Right-click Team->Share Project

 commit all files

 

2.3 Edit the project pom.xml file

<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>cn.jaychang</groupId>
	<artifactId>testapp</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>testapp</name>
	<url>http://maven.apache.org</url>

	<distributionManagement>
		<repository>
			<id>nexus-releases</id>
			<name>Internal Release Repository</name>
			<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>nexus-snapshots</id>
			<name>Internal Snapshot Repository</name>
			<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

	<scm>
		<connection>scm:svn:svn://127.0.0.1/javadev/testapp/trunk/</connection>
		<developerConnection>scm:svn:svn://127.0.0.1/javadev/testapp/trunk/</developerConnection>
		<url>svn://127.0.0.1/javadev/testapp/trunk/</url>
	</scm>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-release-plugin</artifactId>
				<version>2.5.2</version>
				<configuration>
					<tagBase>svn://127.0.0.1/javadev/testapp/tags/</tagBase>
					<branchBase>svn://127.0.0.1/javadev/testapp/branches</branchBase>
					<tagNameFormat>@{version}</tagNameFormat>
					<username>${scm.username}</username>
					<password>${scm.password}</password>
					<checkModificationExcludes>
						<checkModificationExclude>.project</checkModificationExclude>
						<checkModificationExclude>.settings</checkModificationExclude>
						<checkModificationExclude>.classpath</checkModificationExclude>
					</checkModificationExcludes>
			       </configuration>
			</plugin>
		</plugins>
	</build>
</project>

 

Next, make sure all your code is committed. If you have uncommitted code, the release plugin will report an error. Since you are about to release the version, it means that the code is stable, so either commit the code or put the local changes. abandoned.

 

2.4 Enter the testapp project directory

Execute better under CMD

During the execution of mvn release:prepare
, you will encounter this prompt:
What is the release version for "Unnamed - org.myorg:myapp:jar:1.0-SNAPSHOT"? (xxx.xxx.xxx) 0.0.1: :
- "What version do you want to release -0.0.1-SNAPSHOT? The default is 0.0.1." All I want is 0.0.1, just press Enter.
What is SCM release tag or label for "Unnamed - xxx.xxx.xxx:jar:0.0.1-SNAPSHOT"? (xxx.xxx.xxx) 0.0.1: :
——"What is the name of the released tag? Default 0.0.1." I still want the default value, just press Enter.
What is the new development version for "Unnamed - xxx.xxx.xxx:jar:0.0.1-SNAPSHOT"? (xxx.xxx.xxx) 0.0.2-SNAPSHOT: :
—— "What is the new version on trunk? The default is 0.0.2-SNAPSHOT." Ha, the release plugin will automatically update the version to 0.0.2-SNAPSHOT for me, very good, just press Enter.
Then the screen is swiped, maven is building our project, and some svn operations are performed, you can check the log carefully.
So what is the result? You can browse the svn repository:
we have one more tag:

 


 
 

This is version 0.0.1 that needs to be released.
Look at the POM in the trunk, and its version is automatically upgraded to 0.0.2-SNAPSHOT.
Isn't that what we want? Wait, something seems to be missing, by the way, 0.0.1 hasn't been released to the repository yet.
Hold your breath again and execute:

mvn release:peform

 

maven-release-plugin will automatically help us check out the tag we just marked, and then package and distribute it to the remote Maven repository. At this point, the upgrade, tagging, and publishing of the entire version are completed. We can see the officially released version 0.0.1 in the remote Maven repository.

This is an automated  , official  version release!

 

 

At this point, the version in the project's pom.xml becomes 0.0.2-SNAPSHOT

<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>cn.jaychang</groupId>
	<artifactId>testapp</artifactId>
	<version>0.0.2-SNAPSHOT</version>
	<packaging>jar</packaging>
...

 

 

There is a problem

 

Maven multi-module project, there is no successful experiment yet.

 Multi-module project structure (it does not seem to be synchronized with SVN here, it may be a problem with Eclipse Mar, in fact, this project has been checked in to SVN):


 

<?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>

	<groupId>cn.jaychang.mybbs</groupId>
	<artifactId>mybbs-group</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>pom</packaging>
	<name>myapp</name>
	<url>http://maven.apache.org</url>

	<distributionManagement>
		<repository>
			<id>nexus-releases</id>
			<name>Internal Release Repository</name>
			<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>nexus-snapshots</id>
			<name>Internal Snapshot Repository</name>
			<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

	<scm>
		<connection>scm:svn:svn://127.0.0.1/javadev/mybbs/trunk/</connection>
		<developerConnection>scm:svn:svn://127.0.0.1/javadev/mybbs/trunk/</developerConnection>
		<url>svn://127.0.0.1/javadev/mybbs/trunk/</url>
	</scm>

	<modules>
		<module>mybbs-parent</module>
		<module>mybbs-common</module>
		<module>mybbs-business</module>
		<module>mybbs-web</module>
	</modules>
	<build>
		
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-release-plugin</artifactId>
				<version>2.5.2</version>
				<configuration>
					<tagBase>svn://127.0.0.1/javadev/mybbs/tags/</tagBase>
					<tagNameFormat>v@{project.version}</tagNameFormat>
					<username>${scm.username}</username>
					<password>${scm.password}</password>
					 <checkModificationExcludes>  
                        <checkModificationExclude>.project</checkModificationExclude>  
                        <checkModificationExclude>.settings</checkModificationExclude>
                        <checkModificationExclude>.classpath</checkModificationExclude>  
                    </checkModificationExcludes>
				</configuration>
			</plugin>
		</plugins>
	</build>

 
 

Always report in mvn release:prepare stage

Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.2:prepare (default-cli) on project mybbs-group: Cannot prepare the release because you have local modifications :

[ERROR] [mybbs-common\.classpath:unknown]
[ERROR] [mybbs-common\.project:unknown]
[ERROR] [mybbs-parent\.project:unknown]
[ERROR] [mybbs-web\.classpath:unknown]
[ERROR] [mybbs-web\.project:unknown]
[ERROR] [pom.xml:modified]



 

 From the error, the pom.xml of mybbs

的配置 <checkModificationExcludes> 
                        <checkModificationExclude>.project</checkModificationExclude> 
                        <checkModificationExclude>.settings</checkModificationExclude>
                        <checkModificationExclude>.classpath</checkModificationExclude> 
                    </checkModificationExcludes>

But for mybbs-common, mybbs-business, mybbs-web modoule modules did not work.

This problem has been bothering me for a long time, and I don't know how to solve it. If anyone knows, please enlighten me.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326397540&siteId=291194637