Skip to content

Commit 41cca69

Browse files
authored
[Gradle] Added the possibility to completely exclude modules from the scan (fix for issue #1413) (#1418)
Added the possibility to completely exclude modules from the scan (fix for issue #1413) Signed-off-by: Roland Asmann <[email protected]>
1 parent e9f714d commit 41cca69

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

docs/ENV.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ The following environment variables are available to configure the bom generatio
2626
| GRADLE_DEPENDENCY_TASK | By default cdxgen use the task "dependencies" to collect packages. Set to override the task name. |
2727
| GRADLE_INCLUDED_BUILDS | Comma-separated list of 'includedBuilds' modules that should be scanned on top of all the modules of your projects. Since includedBuilds can't be found automatically, they have to be listed here. Use gradle-conventions (include the ':'-prefix) for the names. |
2828
| GRADLE_RESOLVE_FROM_NODE | If some of your gradle modules are included from node (eg when using expo or react-native), set this to true to use the npm-packages as your dependencies. The big advantage of this, is that the generated purls will be of actually known components (eg in OSS Index) instead of generic names for the packages. |
29-
| GRADLE_SKIP_MODULES | Comma-separated list of modules to skip during the "dependencies" task. This can be useful if you have modules that would fail the gradle build, eg when they do not have dependencies in the given configuration. Use "root" if the top most module should be skipped, use their gradle-name (so WITH leading ":") for all others. |
29+
| GRADLE_SKIP_MODULE_DEPENDENCIES | Comma-separated list of modules to skip during the "dependencies" task. This can be useful if you have modules that would fail the gradle build, eg when they do not have dependencies in the given configuration. Use "root" if the top most module should be skipped, use their gradle-name (so WITH leading ":") for all others. |
30+
| GRADLE_SKIP_MODULES | Comma-separated list of modules to skip for both "properties" and "dependencies" task. Use the gradle-name (so WITH leading ":"). NOTICE: when using this, neither the configured ID (group, name & version) nor the dependencies of these modules will be available! |
3031
| SBT_CACHE_DIR | Specify sbt cache directory. Useful for class name resolving |
3132
| FETCH_LICENSE | Set this variable to `true` or `1` to fetch license information from the registry. npm and golang |
3233
| SEARCH_MAVEN_ORG | If maven metadata is missing in jar file, a search is performed on search.maven.org. Set to `false` or `0` to disable search. (defaults to `true`) |

lib/cli/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,29 +1684,36 @@ export async function createJavaBom(path, options) {
16841684
parentComponent = rootGradleModule;
16851685
// Get the sub-project properties and set the root dependencies
16861686
if (allProjectsStr?.length) {
1687+
const modulesToSkip = process.env.GRADLE_SKIP_MODULES
1688+
? process.env.GRADLE_SKIP_MODULES.split(",")
1689+
: [];
1690+
16871691
const parallelPropTaskOut = executeParallelGradleProperties(
16881692
gradleRootPath,
1689-
allProjectsStr,
1693+
allProjectsStr.filter((module) => !modulesToSkip.includes(module)),
16901694
);
16911695
const splitPropTaskOut = splitOutputByGradleProjects(
16921696
parallelPropTaskOut,
16931697
["properties"],
16941698
);
16951699

1696-
for (const [key, propTaskOut] of splitPropTaskOut.entries()) {
1697-
const retMap = parseGradleProperties(propTaskOut, key);
1700+
for (const subProject of allProjectsStr) {
1701+
const retMap = parseGradleProperties(
1702+
splitPropTaskOut.get(subProject),
1703+
subProject,
1704+
);
16981705
const rootSubProject = retMap.rootProject;
16991706
if (rootSubProject) {
17001707
const rootSubProjectObj = await buildObjectForGradleModule(
1701-
rootSubProject,
1708+
rootSubProject === "root" ? subProject : rootSubProject,
17021709
retMap.metadata,
17031710
);
17041711
if (!allProjectsAddedPurls.includes(rootSubProjectObj["purl"])) {
17051712
allProjects.push(rootSubProjectObj);
17061713
rootDependsOn.push(rootSubProjectObj["bom-ref"]);
17071714
allProjectsAddedPurls.push(rootSubProjectObj["purl"]);
17081715
}
1709-
gradleModules.set(key, rootSubProjectObj);
1716+
gradleModules.set(subProject, rootSubProjectObj);
17101717
}
17111718
}
17121719
// Bug #317 fix
@@ -1733,9 +1740,14 @@ export async function createJavaBom(path, options) {
17331740
: "dependencies";
17341741

17351742
const gradleSubCommands = [];
1736-
const modulesToSkip = process.env.GRADLE_SKIP_MODULES
1743+
let modulesToSkip = process.env.GRADLE_SKIP_MODULES
17371744
? process.env.GRADLE_SKIP_MODULES.split(",")
17381745
: [];
1746+
if (process.env.GRADLE_SKIP_MODULE_DEPENDENCIES) {
1747+
modulesToSkip = modulesToSkip.concat(
1748+
process.env.GRADLE_SKIP_MODULE_DEPENDENCIES.split(","),
1749+
);
1750+
}
17391751
if (!modulesToSkip.includes("root")) {
17401752
gradleSubCommands.push(gradleDepTask);
17411753
}

lib/helpers/utils.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,28 +2640,34 @@ export async function parseGradleDep(
26402640
let scope = undefined;
26412641
let profileName = undefined;
26422642
if (retMap?.projects) {
2643+
const modulesToSkip = process.env.GRADLE_SKIP_MODULES
2644+
? process.env.GRADLE_SKIP_MODULES.split(",")
2645+
: [];
26432646
const modulesToScan = retMap.projects.filter(
26442647
(module) => !gradleModules.has(module),
26452648
);
26462649
if (modulesToScan.length > 0) {
26472650
const parallelPropTaskOut = executeParallelGradleProperties(
26482651
gradleRootPath,
2649-
modulesToScan,
2652+
modulesToScan.filter((module) => !modulesToSkip.includes(module)),
26502653
);
26512654
const splitPropTaskOut = splitOutputByGradleProjects(
26522655
parallelPropTaskOut,
26532656
["properties"],
26542657
);
26552658

2656-
for (const [key, propTaskOut] of splitPropTaskOut.entries()) {
2657-
const propMap = parseGradleProperties(propTaskOut, key);
2659+
for (const module of modulesToScan) {
2660+
const propMap = parseGradleProperties(
2661+
splitPropTaskOut.get(module),
2662+
module,
2663+
);
26582664
const rootSubProject = propMap.rootProject;
26592665
if (rootSubProject) {
26602666
const rootSubProjectObj = await buildObjectForGradleModule(
2661-
rootSubProject,
2667+
rootSubProject === "root" ? module : rootSubProject,
26622668
propMap.metadata,
26632669
);
2664-
gradleModules.set(key, rootSubProjectObj);
2670+
gradleModules.set(module, rootSubProjectObj);
26652671
}
26662672
}
26672673
}

0 commit comments

Comments
 (0)