fossa-cli icon indicating copy to clipboard operation
fossa-cli copied to clipboard

Question: how to exclude gradle modules (subprojects)

Open NielsDoucet opened this issue 3 years ago • 7 comments

Given the following gradle project structure:

  • project/
    • build.gradle
    • settings.gradle
    • api/
      • build.gradle
    • core/
      • build.gradle
    • integration-tests/
      • build.gradle
    • utils/
      • build.gradle

and the output of list-targets

$ ./fossa list-targets
[ INFO] Found project: gradle@./
[ INFO] Found target: gradle@./::api
[ INFO] Found target: gradle@./::core
[ INFO] Found target: gradle@./::integration-tests
[ INFO] Found target: gradle@./::utils

and .fossa.yml

version: 3

targets:
  only:
    - type: gradle

paths:
  exclude:
    - integration-tests

Is there a way to tell fossa to exclude the ./::integration-tests target from the analysis? I thought a simple path exclusion would work (e.g. see above), but in the case of gradle subprojects, this doesn't seem to be the case, as they're all considered to be in the ./ root path.

NielsDoucet avatar May 05 '22 11:05 NielsDoucet

@NielsDoucet Which version of fossa-cli are you using? I'm unable to reproduce on 3.2.10:

$ tree
.
├── a
│   └── build.gradle
└── b
    └── build.gradle

2 directories, 2 files

$ fossa list-targets
[ INFO] Found project: gradle@a/
[ INFO] Found target: gradle@a/:
[ INFO] Found project: gradle@b/
[ INFO] Found target: gradle@b/:

If I add this to my .fossa.yml:

targets:
  only:
    - type: gradle

paths:
  exclude:
    - b

Then only the project in directory a is analyzed:

$ fossa analyze --output
[ INFO] Analyzing gradle project at /home/rolodato/source/collibra/gradle-paths/a/
[...]

Removing paths.exclude causes both directories to be analyzed:

$ rm .fossa.yml
$ fossa analyze --output
[ INFO] Analyzing gradle project at /home/rolodato/source/collibra/gradle-paths/a/
[ INFO] Analyzing gradle project at /home/rolodato/source/collibra/gradle-paths/b/
[...]

rolodato avatar May 05 '22 17:05 rolodato

Remember that this is a multi-module gradle project. You're testing 2 separate gradle projects by running the analyze task in their parent directory.

$ tree
.
├── a
│   └── build.gradle
├── b
│   └── build.gradle
├── build.gradle
└── settings.gradle

2 directories, 4 files

This is the equivalent tree you should be testing. And the settings.gradle file should include the following:

include("a")
include("b")

In order to make this a multi-module gradle project.

NielsDoucet avatar May 05 '22 18:05 NielsDoucet

@meghfossa -- hi! I met with @NielsDoucet today and he called this out as being a major priority. It wasn't clear to me how / whether the Maven depgraph work you referenced above would address the gradle module exception requirement; when you have a moment can you please help clarify this question? Thank you!!

scbrent avatar Sep 01 '22 20:09 scbrent

Hi @NielsDoucet, can you try the following?

version: 3
targets:
  only:
    - type: gradle
  exclude:
    - type: gradle
      path: ./
      target: ':integration-tests'

I believe this should exclude integration-tests from the analysis.

meghfossa avatar Sep 09 '22 17:09 meghfossa

@meghfossa that does the trick indeed, thank you very much!

cc @scbrent

NielsDoucet avatar Sep 26 '22 14:09 NielsDoucet

A few follow-up questions:

  1. is this documented somewhere?
  2. how can I exclude multiple targets? do I need the 3-line filter for each of them, or can I specify multiple targets in one of these entries?

NielsDoucet avatar Sep 26 '22 14:09 NielsDoucet

@NielsDoucet

  1. Unfortunately not yet - I have an open PR now https://github.com/fossas/fossa-cli/pull/1059 that should add this into the docs
  2. Yes, you would need to have multiple entries. example:
version: 3
targets:
  only:
    - type: gradle
  exclude:
    - type: gradle
      path: ./
      target: ':app'
    - type: gradle
      path: ./
      target: ':utilities'

meghfossa avatar Sep 27 '22 15:09 meghfossa

Closing this issue, feel free to comment if you still need help with this. Thanks!

rolodato avatar Oct 25 '22 16:10 rolodato