-
Notifications
You must be signed in to change notification settings - Fork 455
Adding recipe for DoesNotIncludeDependency
for Gradle (Maven had one already), to allow for checking whether a dependency is not included.
#5725
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
Conversation
rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DoesNotIncludeDependency.java
Show resolved
Hide resolved
…OM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725
rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DoesNotIncludeDependency.java
Outdated
Show resolved
Hide resolved
rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DoesNotIncludeDependency.java
Outdated
Show resolved
Hide resolved
26793b8
to
b4fbdb2
Compare
Still working on the tests to include ones for specific configurations and transitive dependencies, but getting closer. |
rewrite-gradle/src/test/java/org/openrewrite/gradle/search/DoesNotIncludeDependencyTest.java
Outdated
Show resolved
Hide resolved
b4fbdb2
to
0c0443a
Compare
rewrite-gradle/src/test/java/org/openrewrite/gradle/search/DoesNotIncludeDependencyTest.java
Outdated
Show resolved
Hide resolved
rewrite-maven/src/test/java/org/openrewrite/maven/search/DoesNotIncludeDependencyTest.java
Show resolved
Hide resolved
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("configurationsAndMatches") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would something like this help readability perhaps? Took me 20 seconds with Claude, so don't go changing things manually:
@CsvSource(
useHeadersInDisplayName = true, textBlock = """
configuration, annotationProcessor, api, implementation, compileOnly, runtimeOnly, testImplementation, testCompileOnly, testRuntimeOnly
annotationProcessor, true, false, false, false, false, false, false, false
compileClasspath, false, true, true, true, false, false, false, false
runtimeClasspath, false, true, true, false, true, false, false, false
testCompileClasspath, false, true, true, false, false, true, true, false
testRuntimeClasspath, false, true, true, false, true, true, false, true
""")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I've never used the @CsvSource
with textBlock
before, but yeah, something like that would also work.
@CsvSource({"compile,compile", "compile,test"}) | ||
@CsvSource({"runtime,compile", "runtime,test",}) | ||
@CsvSource({"test,test"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit surprised by the repeated annotation here; is there a logic to the grouping that I'm missing? Might a textBlock make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was grouping them by the existing scope of the dependency per row. It was more for my own legibility than anything else.
rewrite-maven/src/test/java/org/openrewrite/maven/search/DoesNotIncludeDependencyTest.java
Outdated
Show resolved
Hide resolved
rewrite-gradle/src/main/java/org/openrewrite/gradle/search/DoesNotIncludeDependency.java
Outdated
Show resolved
Hide resolved
Mostly looks good already; couple questions & comments, but nothing blocking. Once addressed we can merge. |
…e already), to allow for checking whether a dependency is not included.
…sNotIncludeDependency.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…pendencyInsight` to showcase passing `configuration`. Adding `DoesNotIncludeDependency` tests (still need to add more).
…sts to match naming convention of the Maven version's tests.
… Maven version. I still want to change it a bit so that the test body can be shared for situations that behave the same (like `onlyDirect` has not effect when there is a direct dependency present, so all those tests are the same for whether it's `null`, `true` or `false` for that)
e45bea1
to
a69aeb7
Compare
I think the only things I didn't end up changing right now were the suggestions for using |
rewrite-maven/src/test/java/org/openrewrite/maven/search/DoesNotIncludeDependencyTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved already. Thanks for the help here!
…OM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725
…OM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725
…OM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725
…OM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725
…OM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725
…OM or build.gradle have a dependency on `org.testng:testng`. (#760) * Adding dependency guards to the Junit 4 -> 5 migration for when the POM or build.gradle have a dependency on `org.testng:testng`. Relies on openrewrite/rewrite#5725 * Updating `DoesNotIncludeDependency` recipe call to be the shared one in `rewrite-java-dependencies` * Avoid tests passing for the wrong reason (class present) * Only pass testng dependency into the single test that needs it * Match any testng dependency * Adding TestNgGuard scanning recipe. Needs refinement, but this is a first pass * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Making separate `TestNgGuard` tests and cleaning up other code * Cleanup of import Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Made the `TestNgGuard` more flexible for situations where there isn't an enclosing project for a source file, which was a majority of our existing tests. - If it figures out it's a loose file not in a `JavaProject`, it can't ensure project scope anyway, so falls back to solely whether the file itself has a TestNG dependency or uses TestNG types instead for those * Do not use getters internally * Adopt `ModuleHasDependency` and drop odd test: only look at dependencies Assuming classes can not be present without those dependencies * Revert change to `TestNgToAssertJTest` * Drop tests that were showing improbable use of types * Switching to using the new `invertMarking` option on `ModuleHasDependency` for the TestNG guard for JUnit --------- Co-authored-by: Tim te Beek <tim@moderne.io> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
What's changed?
What's your motivation?
I have a need for being able to detect that a dependency is not included to decide whether to proceed with additional migrations or not. Maven already had a version of this, but Gradle was missing one, and I want to be thorough in this precondition check.
I have not written tests for this quite yet. All of the tests for the Maven version appear to be commented out for some reason, though I do want to add a couple of examples in tests still.
One thing to point out is that it does not include the same
directOnly
option as the Maven version, as the way the implementations ofDependencyInsight
is processing dependencies between Maven and Gradle is slightly different, and that class does not take the option in the Gradle version.Checklist