[MARTIFACT-35] Compare goal should fail build when comparison was unsuccessful
This closes #12
diff --git a/src/it/compare-mono/invoker.properties b/src/it/compare-mono/invoker.properties
index 339a145..fe14eb3 100644
--- a/src/it/compare-mono/invoker.properties
+++ b/src/it/compare-mono/invoker.properties
@@ -17,3 +17,4 @@
invoker.goals.1=clean install
invoker.goals.2=clean package artifact:compare
+invoker.buildResult.2=failure
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
index a6b2e6d..3414471 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
@@ -192,12 +192,12 @@
if ( ko + missing > 0 )
{
- getLog().warn( "Reproducible Build output summary: " + MessageUtils.buffer().success( ok + " files ok" )
+ getLog().error( "Reproducible Build output summary: " + MessageUtils.buffer().success( ok + " files ok" )
+ ", " + MessageUtils.buffer().failure( ko + " different" )
- + ( ( missing == 0 ) ? "" : ( ", " + MessageUtils.buffer().warning( missing + " missing" ) ) ) );
- getLog().warn( "see " + MessageUtils.buffer().project( "diff " + relative( referenceBuildinfo ) + " "
+ + ( ( missing == 0 ) ? "" : ( ", " + MessageUtils.buffer().failure( missing + " missing" ) ) ) );
+ getLog().error( "see " + MessageUtils.buffer().project( "diff " + relative( referenceBuildinfo ) + " "
+ relative( buildinfoFile ) ).toString() );
- getLog().warn( "see also https://maven.apache.org/guides/mini/guide-reproducible-builds.html" );
+ getLog().error( "see also https://maven.apache.org/guides/mini/guide-reproducible-builds.html" );
}
else
{
@@ -241,6 +241,11 @@
}
copyAggregateToRoot( buildcompare );
+
+ if ( ko + missing > 0 )
+ {
+ throw new MojoExecutionException( "Build artifacts are different from reference" );
+ }
}
// { filename, diffoscope }
@@ -268,8 +273,8 @@
if ( issue != null )
{
String diffoscope = diffoscope( artifact, referenceDir );
- getLog().warn( issue + " mismatch " + MessageUtils.buffer().strong( actualFilename ) + ": investigate with "
- + MessageUtils.buffer().project( diffoscope ) );
+ getLog().error( issue + " mismatch " + MessageUtils.buffer().strong( actualFilename )
+ + ": investigate with " + MessageUtils.buffer().project( diffoscope ) );
return new String[] { actualFilename, diffoscope };
}
return new String[] { actualFilename, null };