jhipster / jhipster-lite

JHipster Lite ⚡ is a development platform to generate, develop & deploy modern web applications & microservices architecture, step by step - using Hexagonal Architecture :gem:
https://lite.jhipster.tech
Apache License 2.0
466 stars 214 forks source link

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

Closed renanfranca closed 8 months ago

renanfranca commented 8 months ago

Dependencies should be grouped by destination kotlin:S6629

image

The gradleapp from the ./tests-ci/generate.sh gradleapp gradle yml generates the following dependencies at build.gradle.kts

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)
  runtimeOnly(libs.postgresql)
  implementation(libs.liquibase.core)
  implementation(libs.spring.boot.starter.security)
  implementation(libs.jjwt.api)
  runtimeOnly(libs.jjwt.impl)
  runtimeOnly(libs.jjwt.jackson)
  implementation(libs.springdoc.openapi.starter.webmvc.ui)
  implementation(libs.springdoc.openapi.starter.webmvc.api)
  // jhipster-needle-gradle-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
}

I think the solution is to create two new needles for runtimeOnly and testRuntimeOnly to ensure the correct order. Here is the correct order accepted by the sonar:

dependencies {
  // Implementation 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-dependencies

  runtimeOnly(libs.postgresql)
  runtimeOnly(libs.jjwt.impl)
  runtimeOnly(libs.jjwt.jackson)

  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
}

The code smell was detected after start running the local sonar for gradleapp at github_actions: image

murdos commented 8 months ago

I think the solution is to create two new needles for runtimeOnly and testRuntimeOnly to ensure the correct order. Here is the correct order accepted by the sonar:

@renanfranca : The only scopes that are currently mapped are compileOnly and runtimeOnly, see https://github.com/jhipster/jhipster-lite/blob/524bbf0192d906978e3cb2f47aaa0767082197d7/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/gradle/GradleCommandHandler.java#L118-L123