Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(README): update the Gradle section #295

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

borisrizov-zf
Copy link

Summary

The bash version using grep is inconsistent, that's why an extensive Gradle version, written in Groovy, is used to download the dash.jar resolve all dependencies and run the Dash tool on them.

This allows for usage in ci/cd environments as the task will fail if the Dash run fails.

The bash version using grep is inconsistent, that's why an extensive
Gradle version, written in Groovy, is used to download the `dash.jar`
resolve all dependencies and run the Dash tool on them.

This allows for usage in ci/cd environments as the task will fail if the
Dash run fails.
Comment on lines +433 to +436
logger.lifecycle("Removing 'dash.jar'")
file('dash.jar').delete()
logger.lifecycle("Removing 'deps.txt'")
file('deps.txt').delete()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.lifecycle("Removing 'dash.jar'")
file('dash.jar').delete()
logger.lifecycle("Removing 'deps.txt'")
file('deps.txt').delete()
doLast {
logger.lifecycle("Removing 'dash.jar'")
file('dash.jar').delete()
logger.lifecycle("Removing 'deps.txt'")
file('deps.txt').delete()
}

Should be wrapped inside a doLast-block so it is not executed during configuration phase

}

def sorted = deps.unique().sort()
filtered.each { logger.quiet("{}", it) }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filtered.each { logger.quiet("{}", it) }
sorted.each { logger.quiet("{}", it) }

typo?


def sorted = deps.unique().sort()
filtered.each { logger.quiet("{}", it) }
file("deps.txt").write(sorted.join('\n'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: can we rename the file to dependencies.txt pretty please? :) If yes, keep in mind to rename all occurrences in all files


```
deps.txt
dasj.jar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dasj.jar
dash.jar

typo

dasj.jar
```

To use Dash directly within Gradle, add the following code to your `build.gradle`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootProject build.gradle or app / lib build.gradle? I guess you mean the rootProject build.gradle here as you also call it with without a project here

Comment on lines +409 to +415
repositories {
maven {
// Used to resolve Dash License Tool
// Dash has a maven plugin, BUT is not resolvable through mavenCentral()
url = uri("https://repo.eclipse.org/content/repositories/dash-licenses/")
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed?
You don't resolve the Dash License Tool using a maven dependency but by downloading a file via url


def sorted = deps.unique().sort()
filtered.each { logger.quiet("{}", it) }
file("deps.txt").write(sorted.join('\n'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a different location would be preferable, e.g. $rootDir/build/oss

Advantage: It would automatically be cleaned with a ./gradlew clean

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional Findings:

  • optional: encapsulate the code in a separate gradle file (e.g. dash.gradle) and just apply the script where needed (rootProject, subprojects, both...) - it's cleaner than "polluting" the build.gradle with different contexts and different tasks. However it might get a bit finicky with the plugin you apply, as you can't use the plugin-block in other gradle scripts than settings.gradle and build.gradle
  • when executing dashDependencies not on the rootProject but on a subproject the results will contain an entry like this: project :app. These entries should be excluded from the dependencies and therefore not be part of the dependencies.txt
  • right now the dashDependencies task is only executed on the rootProject, however each subproject will have it's own dependency tree and configurations. Basically you need to create and execute your task for each subproject, similar like this:
subprojects {
    tasks.register('dashDependencies') {
        description = "Output all project dependencies as a flat list and save an intermediate file 'deps.txt'."
        group = 'License'

        doLast {
            def deps = []
            project.configurations.each { conf ->
                if (conf.canBeResolved && conf.getName() != 'archives' && conf.getName() != 'default') {
                    deps.addAll(conf.incoming.resolutionResult.allDependencies
                            .findAll({ it instanceof ResolvedDependencyResult })
                            .collect { ResolvedDependencyResult dep ->
                                "${dep.selected}"
                            })
                }
            }
            def sorted = deps.unique().sort()
            mkdir "$rootDir/build/oss/${project.name}"
            file("$rootDir/build/oss/${project.name}/dependencies.txt").write(sorted.join('\n'))
        }
    }
}

Execute ./gradlew dashDependenciesand check the results for each submodule here: $rootDir/build/oss/. All of them should be clarified using the dash license tool. It's better to scan to much than scanning to few :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have something similar in place here (we don't scan with gradle, we just provide the dependencies.txt for the CI):

Besides the few "project"-entries the recognition of both our scripts is on the same level (if executed on all subprojects). However I prefer your way of collecting the dependencies, because it's less error prone than using the regular expressions to parse them.

Maybe you can pick the best of both our worlds so we get something that is top-notch :)

Once its more fine-tuned we will definitely use it in favor of our dash.sh in our project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants