You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ It does so by:
7
7
* Enforcing [gitflow](http://nvie.com/posts/a-successful-git-branching-model/) version heuristics in [Maven](http://maven.apache.org/) projects.
8
8
* Coercing Maven to gracefully support the gitflow workflow without imposing complex CI job configurations or complex Maven setups.
9
9
* Setting distributionManagement repositories (for things like [maven-deploy-plugin](https://maven.apache.org/plugins/maven-deploy-plugin/)) based upon the current git branch.
10
-
* SCM tagging builds for the master branch, using the CI server's repository connection information. (Zero Maven scm configuration necessary)
10
+
* SCM tagging builds for the master branch. You can use the project SCM definition, or if you omit it, you can resolve the CI server's repository connection information. (Zero Maven scm configuration necessary)
11
11
* Promoting existing tested (staged) artifacts for release, rather than re-building the artifacts. Eliminates the risk of accidental master merges or commits resulting in untested code being released, and provides digest hash traceability for the history of artifacts.
12
12
* Enabling the decoupling of repository deployment and execution environment delivery based on the current git branch.
13
13
* Automated deployment, promotion, and delivery of projects without the [maven-release-plugin](http://maven.apache.org/maven-release/maven-release-plugin/) or some other [*almost there* solution](https://axelfontaine.com/blog/final-nail.html).
14
+
* Customizing maven project and system properties based upon the current branch being built. This allows test cases to target different execution environments without changing the artifact results.
14
15
15
16
# Why would I want to use this?
16
17
@@ -34,10 +35,14 @@ All of the solutions to these issues are implemented independently in different
34
35
35
36
1. Make sure you have a your Project SCM configured for your git repository, or that your build server sets environment variables for git branches and git URLs.
36
37
Out of the box, the plugin will try to resolve the git branch based upon the SCM definition on your maven project, or fall back to the environment variables set by Jenkins and Hudson.
37
-
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly...
38
+
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly with all the features...
<!-- The plugin will read the git branch ang git url by resolving these properties at run-time -->
57
-
<gitBranchExpression/>
58
61
</configuration>
59
62
<executions>
60
63
<execution>
@@ -90,24 +93,24 @@ In practice, the Maven versions should:
90
93
91
94
* Be synchronized with release branch and hotfix branch names.
92
95
* Never be -SNAPSHOT in the master branch, release, or hotfix branches.
93
-
* Always be -SNAPSHOT in the development branch.
96
+
* Always be -SNAPSHOT in the develop branch.
94
97
* Be irrelevant if there's no git branch resolvable from your environment.
95
98
96
99
The `enforce-versions` goal asserts these semantics when it can resolve the `gitBranchExpression`.
97
100
98
101
The goal accomplishes this by checking the Maven pom.xml version value, and asserting the -SNAPSHOT status, as well as matching the current branch name
99
-
against regular expressions, extracting version numbers from the branch names where applicable. If a regex specifies a subgroup 1, the content of that
100
-
subgroup is asserted to equal the version defined in the pom.xml.
102
+
against regular expressions, extracting version numbers from the branch names where applicable. If a regex specifies subgroups, the content of the
103
+
last subgroup is asserted to equal the version defined in the pom.xml.
101
104
102
105
The following properties change the behavior of this goal:
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | n/a | Maven property expression to resolve in order to determine the current git branch |
107
-
| masterBranchPattern | origin/master | No | Regex. When matched, signals the master branch is being built. Note the lack of a subgroup. |
108
-
| releaseBranchPattern | origin/release/(.*) | No | Regex. When matched, signals a release branch being built. Subgroup 1, if present, must match the Maven project version. |
109
-
| hotfixBranchPattern | origin/hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Subgroup 1, if present, must match the Maven project version. |
110
-
| developmentBranchPattern | origin/development| Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
110
+
| masterBranchPattern |(origin/)?master | No | Regex. When matched, signals the master branch is being built. |
111
+
| releaseBranchPattern |(origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. |
112
+
| hotfixBranchPattern |(origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. |
113
+
| developmentBranchPattern |(origin/)?develop| Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
111
114
112
115
## Goal: `retarget-deploy` (Branch Specific Deploy Targets & Staging)
113
116
@@ -190,11 +193,8 @@ The following properties can be configured for this goal:
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
192
195
| gitURLExpression | current git branch resolved from SCM or ${env.GIT_URL} | Maven property expression to resolve for the GIT URL connection to use. |
193
-
| masterBranchPattern | origin/master | Regex. When matched against the resolved value of `gitBranchExpression` this plugin executes the scm:tag goal using the `gitURLExpression` to resolve the git URL to use. |
196
+
| masterBranchPattern |(origin/)?master | Regex. When matched against the resolved value of `gitBranchExpression` this plugin executes the scm:tag goal using the `gitURLExpression` to resolve the git URL to use. |
194
197
| tag | ${project.version} | An expression to use for the SCM tag. |
195
-
| tag.plugin.groupId | org.apache.maven.plugins | The groupId of the plugin to use for tagging. |
196
-
| tag.plugin.artifactId | maven-scm-plugin | The artifactId of the plugin to use for tagging. |
197
-
| tag.plugin.version | 1.9.4 | The version of the plugin to use for tagging. |
198
198
199
199
200
200
## Goal: `promote-master` and the Build Extension. (Copy Staged Artifacts to Releases)
@@ -267,7 +267,7 @@ that the first build deployed into. Once they're attached to the project, the `j
267
267
the artifacts built by the first job into a jboss application server.
268
268
269
269
270
-
## Goal: `set-properties` (Dynamically Set a Maven Project / System Properties)
270
+
## Goal: `set-properties` (Dynamically Set Maven Project / System Properties)
271
271
272
272
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
273
273
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
Copy file name to clipboardExpand all lines: src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -28,13 +28,15 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
28
28
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] is defined as a release branch. The maven project version: [" + project.getVersion() + "] is currently a snapshot version.");
29
29
}
30
30
31
-
// If there is a group 1, expect it to match (exactly) the current projectVersion.
32
-
if (gitMatcher.groupCount() >= 1) {
33
-
if (!gitMatcher.group(1).trim().equals(project.getVersion().trim())) {
34
-
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(1).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
31
+
// Expect the last group on non-master branches to match (exactly) the current projectVersion. (only release / hotfix branches)
32
+
if (gitMatcher.groupCount() >0 && !GitBranchType.MASTER.equals(type)) {
33
+
if (!gitMatcher.group(gitMatcher.groupCount()).trim().equals(project.getVersion().trim())) {
34
+
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(gitMatcher.groupCount()).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] is detected as the gitflow development branch, and expects a maven project version ending with -SNAPSHOT. The maven project version found was: [" + project.getVersion() + "]");
0 commit comments