diff --git a/src/it/makeAggregateBom/verify.groovy b/src/it/makeAggregateBom/verify.groovy index 0bf94816..a2e61429 100644 --- a/src/it/makeAggregateBom/verify.groovy +++ b/src/it/makeAggregateBom/verify.groovy @@ -8,7 +8,7 @@ void assertBomFiles(String path, boolean aggregate) { String analysis = aggregate ? "makeAggregateBom" : "makeBom" assert bomFileXml.text.contains('' + analysis + '') assert bomFileXml.text.contains('compile,provided,runtime,system') - assert bomFileXml.text.contains('true') + assert !bomFileXml.text.contains('') assert bomFileJson.text.contains('"name" : "maven.goal",') assert bomFileJson.text.contains('"value" : "' + analysis + '"') assert bomFileJson.text.contains('"name" : "maven.scopes",') diff --git a/src/it/makeBom/verify.groovy b/src/it/makeBom/verify.groovy index f5770add..6e5c585b 100644 --- a/src/it/makeBom/verify.groovy +++ b/src/it/makeBom/verify.groovy @@ -6,7 +6,7 @@ assert bomFileJson.exists() assert bomFileXml.text.contains('https://github.com/CycloneDX/cyclonedx-maven-plugin') -assert bomFileXml.text.contains('true') +assert !bomFileXml.text.contains('') // Reproducible Builds assert !bomFileJson.text.contains('"serialNumber"') diff --git a/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java b/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java index b2257e6f..0b180474 100644 --- a/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java +++ b/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java @@ -168,8 +168,8 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo { private String[] excludeTypes; /** - * Use the original mechanism for determining whether an artifact is OPTIONAL/REQUIRED, relying on bytecode analysis - * of the compiled classes instead of the maven declaration of optional. + * Use the original mechanism for determining whether a component has OPTIONAL or REQUIRED scope, + * relying on bytecode analysis of the compiled classes instead of the Maven dependency declaration of optional. * * @since 2.7.9 */ @@ -290,7 +290,9 @@ public void execute() throws MojoExecutionException { if (includeTestScope) scopes.add("test"); metadata.addProperty(newProperty("maven.scopes", String.join(",", scopes))); - metadata.addProperty(newProperty("maven.optional", Boolean.toString(!detectUnusedForOptionalScope))); + if (detectUnusedForOptionalScope) { + metadata.addProperty(newProperty("maven.optional.unused", Boolean.toString(detectUnusedForOptionalScope))); + } } final Component rootComponent = metadata.getComponent(); diff --git a/src/test/java/org/cyclonedx/maven/Issue314Test.java b/src/test/java/org/cyclonedx/maven/Issue314OptionalTest.java similarity index 93% rename from src/test/java/org/cyclonedx/maven/Issue314Test.java rename to src/test/java/org/cyclonedx/maven/Issue314OptionalTest.java index e3c0c2b7..e988712d 100644 --- a/src/test/java/org/cyclonedx/maven/Issue314Test.java +++ b/src/test/java/org/cyclonedx/maven/Issue314OptionalTest.java @@ -23,17 +23,17 @@ import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner; /** - * Fix BOM handling of conflicting dependency tree graphs + * Test optional detection as Maven dependency optional vs bytecode analysis of unused. */ @RunWith(MavenJUnitTestRunner.class) @MavenVersions({"3.6.3"}) -public class Issue314Test extends BaseMavenVerifier { +public class Issue314OptionalTest extends BaseMavenVerifier { private static final String ISSUE_314_DEPENDENCY_B = "pkg:maven/com.example.issue_314/dependency_B@1.0.0?type=jar"; private static final String ISSUE_314_DEPENDENCY_C = "pkg:maven/com.example.issue_314/dependency_C@1.0.0?type=jar"; private static final String ISSUE_314_DEPENDENCY_D = "pkg:maven/com.example.issue_314/dependency_D@1.0.0?type=jar"; - public Issue314Test(MavenRuntimeBuilder runtimeBuilder) throws Exception { + public Issue314OptionalTest(MavenRuntimeBuilder runtimeBuilder) throws Exception { super(runtimeBuilder); } @@ -77,6 +77,7 @@ public void testBytecodeDependencyTree() throws Exception { /** * Validate the maven optional components. * - com.example.issue_314:dependency_C:1.0.0 and com.example.issue_314:dependency_D:1.0.0 *should* be marked as optional + * because dependency_A declares dependency_C as optional, which depends on dependency_D */ @Test public void testMavenOptionalDependencyTree() throws Exception { diff --git a/src/test/resources/issue-314/dependency_A/pom.xml b/src/test/resources/issue-314/dependency_A/pom.xml index 27ba8495..821ed06d 100644 --- a/src/test/resources/issue-314/dependency_A/pom.xml +++ b/src/test/resources/issue-314/dependency_A/pom.xml @@ -14,12 +14,6 @@ dependency_A Dependency A - - - 1.8 - 1.8 - - com.example.issue_314 @@ -50,18 +44,6 @@ - - library - 1.4 - true - true - true - false - false - false - false - xml - diff --git a/src/test/resources/issue-314/dependency_B/pom.xml b/src/test/resources/issue-314/dependency_B/pom.xml index 603b8a1b..70ea38d8 100644 --- a/src/test/resources/issue-314/dependency_B/pom.xml +++ b/src/test/resources/issue-314/dependency_B/pom.xml @@ -14,9 +14,4 @@ dependency_B Dependency B - - - 1.8 - 1.8 - diff --git a/src/test/resources/issue-314/dependency_C/pom.xml b/src/test/resources/issue-314/dependency_C/pom.xml index 0a45e02d..c509368a 100644 --- a/src/test/resources/issue-314/dependency_C/pom.xml +++ b/src/test/resources/issue-314/dependency_C/pom.xml @@ -15,11 +15,6 @@ Dependency C - - 1.8 - 1.8 - - com.example.issue_314 diff --git a/src/test/resources/issue-314/dependency_D/pom.xml b/src/test/resources/issue-314/dependency_D/pom.xml index 73d747ad..44f1d99b 100644 --- a/src/test/resources/issue-314/dependency_D/pom.xml +++ b/src/test/resources/issue-314/dependency_D/pom.xml @@ -14,9 +14,4 @@ dependency_D Dependency D - - - 1.8 - 1.8 - diff --git a/src/test/resources/issue-314/pom.xml b/src/test/resources/issue-314/pom.xml index 64d8cb97..1893ddae 100644 --- a/src/test/resources/issue-314/pom.xml +++ b/src/test/resources/issue-314/pom.xml @@ -20,6 +20,8 @@ + 1.8 + 1.8 UTF-8