Skip to content

Commit c7b9cae

Browse files
committed
feat: remove requirement to have project group and version configured
Signed-off-by: skhokhlov <[email protected]>
1 parent 1cae0b7 commit c7b9cae

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/main/java/org/cyclonedx/gradle/SbomGraphProvider.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ class SbomGraphProvider implements Callable<SbomGraph> {
6565
@Override
6666
public SbomGraph call() throws Exception {
6767

68-
if (project.getGroup().equals("")
69-
|| project.getName().isEmpty()
70-
|| project.getVersion().equals("")) {
71-
throw new IllegalStateException("Project group and version are required for the CycloneDx task");
68+
if (project.getGroup().equals("") || project.getVersion().equals("")) {
69+
project.getLogger()
70+
.warn(
71+
"Project group or version are not set for project [{}], will use \"unspecified\"",
72+
project.getName());
7273
}
7374

7475
project.getLogger().info(MESSAGE_RESOLVING_DEPS);

src/main/java/org/cyclonedx/gradle/utils/DependencyUtils.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
public class DependencyUtils {
4040

41+
private static final String UNSPECIFIED = "unspecified";
42+
4143
public static Map<SbomComponentId, SbomComponent> mergeGraphs(
4244
final Map<SbomComponentId, SbomComponent> firstGraph,
4345
final Map<SbomComponentId, SbomComponent> secondGraph) {
@@ -115,7 +117,7 @@ public static SbomComponentId toComponentId(final ResolvedComponentResult node,
115117
type,
116118
projectPath);
117119
} else {
118-
return new SbomComponentId("undefined", node.getId().getDisplayName(), "undefined", type, projectPath);
120+
return new SbomComponentId(UNSPECIFIED, node.getId().getDisplayName(), UNSPECIFIED, type, projectPath);
119121
}
120122
}
121123

@@ -132,9 +134,9 @@ private static String getType(final File file) {
132134
public static String generatePackageUrl(final SbomComponentId componentId) throws MalformedPackageURLException {
133135
return new PackageURL(
134136
PackageURL.StandardTypes.MAVEN,
135-
componentId.getGroup(),
137+
componentId.getGroup().isEmpty() ? UNSPECIFIED : componentId.getGroup(),
136138
componentId.getName(),
137-
componentId.getVersion(),
139+
componentId.getVersion().isEmpty() ? UNSPECIFIED : componentId.getVersion(),
138140
componentId.getQualifiers(),
139141
null)
140142
.canonicalize();

src/test/groovy/org/cyclonedx/gradle/PluginConfigurationSpec.groovy

+5-3
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,13 @@ class PluginConfigurationSpec extends Specification {
552552
.withProjectDir(testDir)
553553
.withArguments("cyclonedxBom", "--stacktrace")
554554
.withPluginClasspath()
555-
.run()
555+
.build()
556556

557557
then:
558-
result.task(":cyclonedxBom").outcome == TaskOutcome.FAILED
559-
assert result.output.contains("Project group and version are required for the CycloneDx task")
558+
result.task(":cyclonedxBom").outcome == TaskOutcome.SUCCESS
559+
File jsonBom = new File(testDir, "build/reports/bom.json")
560+
assert jsonBom.text.contains("pkg:maven/unspecified/hello-world@unspecified?project_path=%3A")
561+
assert result.output.contains("Project group or version are not set for project [hello-world]")
560562
}
561563

562564
def "should include metadata by default"() {

0 commit comments

Comments
 (0)