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

fix gradle dependencies order code smell #9079

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

renanfranca
Copy link
Contributor

Fix #9078

@renanfranca renanfranca self-assigned this Feb 28, 2024
@@ -24,6 +24,7 @@ ext {

dependencies {
// jhipster-needle-gradle-dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to be consistent, I guess that it should be:

Suggested change
// jhipster-needle-gradle-dependencies
// jhipster-needle-gradle-implementation-dependencies

return switch (gradleScope) {
case GradleDependencyScope.TEST_IMPLEMENTATION -> GRADLE_TEST_DEPENDENCY_NEEDLE;
case GradleDependencyScope.RUNTIME_ONLY -> GRADLE_RUNTIME_DEPENDENCY_NEEDLE;
default -> GRADLE_DEPENDENCY_NEEDLE;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to remove TEST_COMPILE_ONLY and TEST_RUNTIME_ONLY values from GradleDependencyScope, since they're currently not used.
And remove this default branch: it's better to fully use pattern matching so each new value will have to be explicitly mapped.
This is related to my comment #9078 (comment): we'll need additional needles for compileOnly and runtimeOnly

Copy link
Contributor

Choose a reason for hiding this comment

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

NB : GradleDependencyScope.API should also be removed :)

@@ -97,7 +101,7 @@ private void addDependencyToBuildGradle(JavaDependency dependency) {
MandatoryReplacer replacer = new MandatoryReplacer(
new RegexNeedleBeforeReplacer(
(contentBeforeReplacement, newText) -> !contentBeforeReplacement.contains(newText),
gradleScope == GradleDependencyScope.TEST_IMPLEMENTATION ? GRADLE_TEST_DEPENDENCY_NEEDLE : GRADLE_DEPENDENCY_NEEDLE
determineGradleDependencyNeedle(gradleScope)
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming suggestion:

Suggested change
determineGradleDependencyNeedle(gradleScope)
needleForGradleDependencyScope(gradleScope)

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3770d3d) to head (4a4d06c).
Report is 9 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main     #9079   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity      2903      2906    +3     
===========================================
  Files            733       733           
  Lines          12527     12531    +4     
  Branches         253       252    -1     
===========================================
+ Hits           12527     12531    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@renanfranca renanfranca force-pushed the 9078-gradle-dependencies-order-code-smell branch from b9271b6 to c039596 Compare February 28, 2024 19:03
@renanfranca
Copy link
Contributor Author

@murdos : Thank you for the fast review! I implemented the bearer minimum to solve the particular reported code smell, when another scenario of dependencies code smells appears I am going to fix it.

I tried ./tests-ci/generate.sh gradleapp gradle yml on my PC and the dependencies got in the correct order:

dependencies {
  implementation(libs.protobuf.java)
  implementation(libs.commons.lang3)
  implementation(platform(libs.spring.boot.dependencies))
  implementation(libs.spring.boot.starter)
  implementation(libs.spring.boot.configuration.processor)
  implementation(libs.spring.boot.starter.validation)
  implementation(libs.spring.boot.starter.web)
  implementation(libs.spring.boot.starter.actuator)
  implementation(libs.spring.boot.starter.data.jpa)
  implementation(libs.hikariCP)
  implementation(libs.hibernate.core)
  implementation(libs.liquibase.core)
  implementation(libs.spring.boot.starter.security)
  implementation(libs.jjwt.api)
  implementation(libs.springdoc.openapi.starter.webmvc.ui)
  implementation(libs.springdoc.openapi.starter.webmvc.api)
  // jhipster-needle-gradle-implementation-dependencies
  runtimeOnly(libs.postgresql)
  runtimeOnly(libs.jjwt.impl)
  runtimeOnly(libs.jjwt.jackson)
  // jhipster-needle-gradle-runtime-dependencies

  testImplementation(libs.protobuf.java.util)
  testImplementation(libs.spring.boot.starter.test)
  testImplementation(libs.reflections)
  testImplementation(libs.testcontainers.postgresql)
  testImplementation(libs.h2)
  testImplementation(libs.spring.security.test)
  testImplementation(libs.cucumber.junit.platform.engine)
  testImplementation(libs.cucumber.java)
  testImplementation(libs.cucumber.spring)
  testImplementation(libs.junit.platform.suite)
  // jhipster-needle-gradle-test-dependencies
}

@@ -118,7 +130,6 @@ private static String applyVersionCatalogReferenceConvention(String rawVersionCa
private static GradleDependencyScope gradleDependencyScope(JavaDependency dependency) {
return switch (dependency.scope()) {
case TEST -> GradleDependencyScope.TEST_IMPLEMENTATION;
case PROVIDED -> GradleDependencyScope.COMPILE_ONLY;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but I would like to keep this one.
Even if the PROVIDED scope is not used yet in any modules in jhlite, it might be used in some custom jhlite, and the mapping is correct, I don't see a reason to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I will keep it 👍. In that case, should I create a needle for compileOnly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it's necessary. Please let me know if you don't have time to do it, I'll do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think it's necessary. Please let me know if you don't have time to do it, I'll do it.

Thank you 😊, I can't do it today, only tomorrow morning. You can do it if you want 👍

@renanfranca renanfranca force-pushed the 9078-gradle-dependencies-order-code-smell branch from c039596 to 4a4d06c Compare February 29, 2024 10:30
@renanfranca
Copy link
Contributor Author

@murdos : I pushed the changes, please, let me know if it's ok 😁

@murdos
Copy link
Contributor

murdos commented Feb 29, 2024

@renanfranca : it's perfect, thanks! Sorry I finally wasn't able to work on it yesterday as I initially proposed.

@murdos murdos merged commit 14b2983 into main Feb 29, 2024
37 checks passed
@murdos murdos deleted the 9078-gradle-dependencies-order-code-smell branch February 29, 2024 11:51
@renanfranca
Copy link
Contributor Author

@renanfranca : it's perfect, thanks! Sorry I finally wasn't able to work on it yesterday as I initially proposed.

It's cool, let's keep going! 😎

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

Successfully merging this pull request may close these issues.

Gradle dependencies order code smell (Dependencies should be grouped by destination kotlin:S6629)
2 participants