Skip to content

Commit d76528b

Browse files
committed
Introduce ChangesetsVersionPolicy
1 parent 2fb5ff6 commit d76528b

17 files changed

Lines changed: 333 additions & 58 deletions

File tree

.changeset/cyan-sloths-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"changesets": minor
3+
---
4+
5+
This change introduces a version policy (`ChangesetsVersionPolicy`) compatible with the Release Maven plugin, together with a flag `useReleasePluginIntegration` (default `false`) on the `prepare` goal. Enabling this flag will disable updating POM versions in `prepare` and only perform changeset processing. Updating versions in POMs can then be delegated to the Release plugin, together with all the other facilities that plugin provides.

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,39 @@ to enable easier management of changelogs and semantically versioned releases.
66
Our goal is to keep compatibility with the files and formats of the original implementation as far as it makes sense, so that
77
users recognize the ways of working and feel at home.
88

9-
This is it, at the moment. Stay tuned for more docs later on, thanks!
9+
This is it, at the moment. Stay tuned for more docs later on, thanks!
10+
11+
# Release Maven Plugin Integration
12+
13+
To delegate versioning to the Release Maven Plugin, you can use the `ChangesetsVersionPolicy` together with the `useReleasePluginIntegration` flag:
14+
15+
```
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>se.fortnox.changesets</groupId>
20+
<artifactId>changesets-maven-plugin</artifactId>
21+
<version>${changesets.plugin.version}</version>
22+
<configuration>
23+
<useReleasePluginIntegration>true</useReleasePluginIntegration> <!-- Disables version updates in prepare goal -->
24+
</configuration>
25+
</plugin>
26+
<plugin>
27+
<artifactId>maven-release-plugin</artifactId>
28+
<version>3.1.1</version>
29+
<configuration>
30+
<projectVersionPolicyId>changesets</projectVersionPolicyId>
31+
<tagNameFormat>v@{project.version}</tagNameFormat>
32+
</configuration>
33+
<dependencies>
34+
<dependency>
35+
<groupId>se.fortnox.changesets</groupId>
36+
<artifactId>changesets-maven-plugin</artifactId>
37+
<version>${changesets.plugin.version}</version>
38+
</dependency>
39+
</dependencies>
40+
</plugin>
41+
</plugins>
42+
```
43+
44+
Goals should then be invoked as `changesets:prepare release:prepare release:perform`. `changesets:release` should *not* be used.

changesets-java/src/main/java/se/fortnox/changesets/VersionCalculator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ public static String getNewVersion(String version, List<Changeset> changes) {
2727
}
2828
return semanticVersion.getVersion();
2929
}
30+
31+
public static String nextDevelopmentVersion(String actualVersion) {
32+
return Optional.ofNullable(Semver.coerce(actualVersion))
33+
.map(semver -> semver.withIncPatch().withPreRelease("SNAPSHOT").getVersion())
34+
.orElseThrow(() -> new IllegalArgumentException("Cannot coerce \"%s\" into a semantic version.".formatted(actualVersion)));
35+
}
3036
}

changesets-maven-plugin/pom.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
<dependency>
4444
<groupId>org.apache.maven.shared</groupId>
4545
<artifactId>maven-shared-utils</artifactId>
46-
<version>3.4.2</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.maven.release</groupId>
49+
<artifactId>maven-release-api</artifactId>
4750
</dependency>
4851
<dependency>
4952
<groupId>org.apache.maven</groupId>
@@ -72,6 +75,18 @@
7275

7376
<build>
7477
<plugins>
78+
<plugin>
79+
<groupId>org.codehaus.plexus</groupId>
80+
<artifactId>plexus-component-metadata</artifactId>
81+
<executions>
82+
<execution>
83+
<id>process-classes</id>
84+
<goals>
85+
<goal>generate-metadata</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
7590
<plugin>
7691
<groupId>org.apache.maven.plugins</groupId>
7792
<artifactId>maven-plugin-plugin</artifactId>
@@ -94,6 +109,18 @@
94109
</execution>
95110
</executions>
96111
</plugin>
112+
<plugin>
113+
<groupId>org.eclipse.sisu</groupId>
114+
<artifactId>sisu-maven-plugin</artifactId>
115+
<executions>
116+
<execution>
117+
<id>generate-index</id>
118+
<goals>
119+
<goal>main-index</goal>
120+
</goals>
121+
</execution>
122+
</executions>
123+
</plugin>
97124
<plugin>
98125
<groupId>org.apache.maven.plugins</groupId>
99126
<artifactId>maven-site-plugin</artifactId>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.4.5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"my-package": patch
3+
---
4+
5+
A tiny change
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"my-package": minor
3+
---
4+
5+
A medium change
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# my-package
2+
3+
## 2.5.0
4+
5+
### Minor Changes
6+
7+
- A medium change
8+
9+
### Patch Changes
10+
11+
- A tiny change
12+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:prepare
2+
invoker.goals.2=release:update-versions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>se.fortnox.maven.it</groupId>
7+
<artifactId>my-package</artifactId>
8+
<version>2.4.6-SNAPSHOT</version>
9+
10+
<description>A simple IT verifying the basic use case.</description>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<artifactId>maven-release-plugin</artifactId>
20+
<version>3.1.1</version>
21+
<configuration>
22+
<projectVersionPolicyId>changesets</projectVersionPolicyId>
23+
<pushChanges>false</pushChanges>
24+
</configuration>
25+
<dependencies>
26+
<dependency>
27+
<groupId>se.fortnox.changesets</groupId>
28+
<artifactId>changesets-maven-plugin</artifactId>
29+
<version>@project.version@</version>
30+
</dependency>
31+
</dependencies>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
</project>

0 commit comments

Comments
 (0)