File tree Expand file tree Collapse file tree 4 files changed +75
-1
lines changed
main/java/org/codehaus/mojo/build
java/org/codehaus/mojo/build/it
projects/create-metadata-it-no-scm Expand file tree Collapse file tree 4 files changed +75
-1
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,20 @@ public abstract class AbstractScmMojo extends AbstractMojo {
135
135
@ Component
136
136
protected ScmManager scmManager ;
137
137
138
+ /**
139
+ * Ignore error when scm url from pom is empty and replace by scm:scmProvider {@link #scmProvider}
140
+ * @since 3.2.1
141
+ */
142
+ @ Parameter (property = "maven.buildNumber.ignoreEmptyScmUrl" , defaultValue = "false" )
143
+ private boolean ignoreEmptyScmUrl ;
144
+
145
+ /**
146
+ * When scm url is empty, scm provider is needed {@link #ignoreEmptyScmUrl}
147
+ * @since 3.2.1
148
+ */
149
+ @ Parameter (property = "maven.buildNumber.scmProvider" , defaultValue = "git" )
150
+ private String scmProvider ;
151
+
138
152
/**
139
153
* Maven Security Dispatcher
140
154
*
@@ -176,8 +190,9 @@ private String decrypt(String str, String server) {
176
190
}
177
191
178
192
protected ScmRepository getScmRepository () throws ScmException {
193
+ String repoUrl = !StringUtils .isBlank (this .scmConnectionUrl ) ? scmConnectionUrl : scmDeveloperConnectionUrl ;
179
194
ScmRepository repository = scmManager .makeScmRepository (
180
- ! StringUtils .isBlank (this . scmConnectionUrl ) ? scmConnectionUrl : scmDeveloperConnectionUrl );
195
+ StringUtils .isBlank (repoUrl ) ? ( ignoreEmptyScmUrl ? "scm:" + scmProvider + ":" : "" ) : repoUrl );
181
196
182
197
ScmProviderRepository scmRepo = repository .getProviderRepository ();
183
198
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ under the License.
25
25
<answer>
26
26
<p>Yes, set the plugin parameter </p> <source> <revisionOnScmFailure></source> <p>to prevent
27
27
the plugin from throwing an exception if SCM information is not found.</p>
28
+ <p>The other option is to use <source>-Dmaven.buildNumber.ignoreEmptyScmUrl=true -Dmaven.buildNumber.scmProvider=git/svn/</source>
29
+ Default is git</p>
28
30
</answer>
29
31
</faq>
30
32
Original file line number Diff line number Diff line change @@ -55,4 +55,19 @@ public void testBasicJsonConfiguration() throws Exception {
55
55
Assert .assertTrue (new File (testDir , "target/generated/build-metadata/build.properties" ).exists ());
56
56
Assert .assertTrue (new File (testDir , "target/classes/build.properties" ).exists ());
57
57
}
58
+
59
+ @ Test
60
+ public void testBasicConfigurationNoScm () throws Exception {
61
+ File projDir = resources .getBasedir ("create-metadata-it-no-scm" );
62
+
63
+ MavenExecution mavenExec = maven .forProject (projDir );
64
+ MavenExecutionResult result = mavenExec .withCliOption ("-e" ).execute ("clean" , "test" );
65
+ result .assertErrorFreeLog ();
66
+
67
+ File testDir = result .getBasedir ();
68
+ Assert .assertTrue (new File (testDir , "target/file1.properties" ).exists ());
69
+ Assert .assertTrue (new File (testDir , "target/xxx/file1.properties" ).exists ());
70
+ Assert .assertTrue (new File (testDir , "target/generated/build-metadata/build.properties" ).exists ());
71
+ Assert .assertTrue (new File (testDir , "target/classes/build.properties" ).exists ());
72
+ }
58
73
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <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" >
3
+
4
+ <modelVersion >4.0.0</modelVersion >
5
+
6
+ <groupId >org.codehaus.mojo.it</groupId >
7
+ <artifactId >build-metadata-it</artifactId >
8
+ <version >1.0-SNAPSHOT</version >
9
+
10
+ <build >
11
+
12
+ <defaultGoal >package</defaultGoal >
13
+
14
+ <plugins >
15
+ <plugin >
16
+ <groupId >org.codehaus.mojo</groupId >
17
+ <artifactId >buildnumber-maven-plugin</artifactId >
18
+ <version >${it-plugin.version} </version >
19
+ <executions >
20
+ <execution >
21
+ <id >useLastCommittedRevision</id >
22
+ <goals >
23
+ <goal >create-metadata</goal >
24
+ </goals >
25
+ <configuration >
26
+ <ignoreEmptyScmUrl >true</ignoreEmptyScmUrl >
27
+ <revisionOnScmFailure >UNKNOWN</revisionOnScmFailure >
28
+ <!-- see outputDirectory + outputName for the default outputFile -->
29
+ <outputFiles >
30
+ <outputFile >${project.build.directory} /file1.properties</outputFile >
31
+ <outputFile >${project.build.directory} /xxx/file1.properties</outputFile >
32
+ </outputFiles >
33
+ <addOutputDirectoryToResources >true</addOutputDirectoryToResources >
34
+ </configuration >
35
+ </execution >
36
+ </executions >
37
+ </plugin >
38
+ </plugins >
39
+
40
+ </build >
41
+
42
+ </project >
You can’t perform that action at this time.
0 commit comments