diff --git a/src/main/java/org/codehaus/mojo/build/AbstractScmMojo.java b/src/main/java/org/codehaus/mojo/build/AbstractScmMojo.java index 68a30c2d..da4c8c6c 100644 --- a/src/main/java/org/codehaus/mojo/build/AbstractScmMojo.java +++ b/src/main/java/org/codehaus/mojo/build/AbstractScmMojo.java @@ -135,6 +135,20 @@ public abstract class AbstractScmMojo extends AbstractMojo { @Component protected ScmManager scmManager; + /** + * Ignore error when scm url from pom is empty and replace by scm:scmProvider {@link #scmProvider} + * @since 3.2.1 + */ + @Parameter(property = "maven.buildNumber.ignoreEmptyScmUrl", defaultValue = "false") + private boolean ignoreEmptyScmUrl; + + /** + * When scm url is empty, scm provider is needed {@link #ignoreEmptyScmUrl} + * @since 3.2.1 + */ + @Parameter(property = "maven.buildNumber.scmProvider", defaultValue = "git") + private String scmProvider; + /** * Maven Security Dispatcher * @@ -176,8 +190,9 @@ private String decrypt(String str, String server) { } protected ScmRepository getScmRepository() throws ScmException { + String repoUrl = !StringUtils.isBlank(this.scmConnectionUrl) ? scmConnectionUrl : scmDeveloperConnectionUrl; ScmRepository repository = scmManager.makeScmRepository( - !StringUtils.isBlank(this.scmConnectionUrl) ? scmConnectionUrl : scmDeveloperConnectionUrl); + StringUtils.isBlank(repoUrl) ? (ignoreEmptyScmUrl ? "scm:" + scmProvider + ":" : "") : repoUrl); ScmProviderRepository scmRepo = repository.getProviderRepository(); diff --git a/src/site/fml/faq.fml b/src/site/fml/faq.fml index 294dbe5f..93160600 100644 --- a/src/site/fml/faq.fml +++ b/src/site/fml/faq.fml @@ -25,6 +25,8 @@ under the License.

Yes, set the plugin parameter

<revisionOnScmFailure>

to prevent the plugin from throwing an exception if SCM information is not found.

+

The other option is to use -Dmaven.buildNumber.ignoreEmptyScmUrl=true -Dmaven.buildNumber.scmProvider=git/svn/ + Default is git

diff --git a/src/test/java/org/codehaus/mojo/build/it/CreateMetadataMojoTest.java b/src/test/java/org/codehaus/mojo/build/it/CreateMetadataMojoTest.java index 0764c8d7..eea6ec07 100644 --- a/src/test/java/org/codehaus/mojo/build/it/CreateMetadataMojoTest.java +++ b/src/test/java/org/codehaus/mojo/build/it/CreateMetadataMojoTest.java @@ -55,4 +55,19 @@ public void testBasicJsonConfiguration() throws Exception { Assert.assertTrue(new File(testDir, "target/generated/build-metadata/build.properties").exists()); Assert.assertTrue(new File(testDir, "target/classes/build.properties").exists()); } + + @Test + public void testBasicConfigurationNoScm() throws Exception { + File projDir = resources.getBasedir("create-metadata-it-no-scm"); + + MavenExecution mavenExec = maven.forProject(projDir); + MavenExecutionResult result = mavenExec.withCliOption("-e").execute("clean", "test"); + result.assertErrorFreeLog(); + + File testDir = result.getBasedir(); + Assert.assertTrue(new File(testDir, "target/file1.properties").exists()); + Assert.assertTrue(new File(testDir, "target/xxx/file1.properties").exists()); + Assert.assertTrue(new File(testDir, "target/generated/build-metadata/build.properties").exists()); + Assert.assertTrue(new File(testDir, "target/classes/build.properties").exists()); + } } diff --git a/src/test/projects/create-metadata-it-no-scm/pom.xml b/src/test/projects/create-metadata-it-no-scm/pom.xml new file mode 100644 index 00000000..88d3e924 --- /dev/null +++ b/src/test/projects/create-metadata-it-no-scm/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + org.codehaus.mojo.it + build-metadata-it + 1.0-SNAPSHOT + + + + package + + + + org.codehaus.mojo + buildnumber-maven-plugin + ${it-plugin.version} + + + useLastCommittedRevision + + create-metadata + + + true + UNKNOWN + + + ${project.build.directory}/file1.properties + ${project.build.directory}/xxx/file1.properties + + true + + + + + + + + + \ No newline at end of file