Splitties / refreshVersions

Life is too short to google for dependencies and versions
https://splitties.github.io/refreshVersions/
MIT License
1.66k stars 107 forks source link

Kotlin compilation when using refreshVersions with io.spring.dependency-management #547

Open juherr opened 2 years ago

juherr commented 2 years ago

⚠️ Current behavior

> Task :compileKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':compileKotlin'
   > Could not resolve all dependencies for configuration ':detachedConfiguration3'.
      > Could not find org.testcontainers:testcontainers-bom:_.
        Searched in the following locations:
          - https://repo.maven.apache.org/maven2/org/testcontainers/testcontainers-bom/_/testcontainers-bom-_.pom
        If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
        Required by:
            project :
      > Could not find org.springframework.cloud:spring-cloud-dependencies:_.
        Searched in the following locations:
          - https://repo.maven.apache.org/maven2/org/springframework/cloud/spring-cloud-dependencies/_/spring-cloud-dependencies-_.pom
        If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
        Required by:
            project :

✅ Expected behavior

> Task :bootRun

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.0)

2022-05-30 14:11:14.033  INFO 851 --- [           main] com.example.demo.DemoApplicationKt       : Starting DemoApplicationKt using Java 17 on MacBook-Pro.local with PID 851 (/Users/juherr/Downloads/demo/build/classes/kotlin/main started by juherr in /Users/juherr/Downloads/demo)
2022-05-30 14:11:14.034  INFO 851 --- [           main] com.example.demo.DemoApplicationKt       : No active profile set, falling back to 1 default profile: "default"
2022-05-30 14:11:14.370  INFO 851 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=8d68904d-fb10-3941-b766-ef717abdd731
2022-05-30 14:11:14.490  INFO 851 --- [           main] com.example.demo.DemoApplicationKt       : Started DemoApplicationKt in 1.054 seconds (JVM running for 1.496)

BUILD SUCCESSFUL in 11s
4 actionable tasks: 1 executed, 3 up-to-date

💣 Steps to reproduce

Using https://start.spring.io/ using the following configuration:

image

And remplacing

extra["springCloudVersion"] = "2021.0.3"
extra["testcontainersVersion"] = "1.17.2"

dependencyManagement {
    imports {
        mavenBom("org.testcontainers:testcontainers-bom:${property("testcontainersVersion")}")
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
    }
}

By

dependencyManagement {
    imports {
        mavenBom("org.testcontainers:testcontainers-bom:2021.0.3")
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:1.17.2")
    }
}

Run: ./gradlew refreshVersionsMigrate will update

dependencyManagement {
    imports {
        mavenBom("org.testcontainers:testcontainers-bom:_")
        mavenBom(Spring.boms.springclmoud)
    }
}

Then ./gradlew bootRun will fail.

📱 Tech info

toddobryan commented 2 years ago

Seeing a similar issue with resolutionStrategy.force(...) being replaced with an underscore, but then refreshVersions doesn't fill it in with the appropriate version.

Flowkap commented 1 year ago

Same issue with Spring.boms.springclmoud (no matter if expanded or using the provided constant). Is there a know workaround? Encountered this by migrating to Spring Boot 3.0.2 (Beside providing the version inside build.kts of course)

Flowkap commented 1 year ago

I spent some time today, as this was the only version not present in the versions.properties due to the bug.

I found a workaround to manually load a version from the versions.properties file with the simple ability to inject anywhere in the gradle.kts files. refreshVersions will still not pick it up of course automatically but at least from a definition point of view its now consistent.

Its not the most beautiful thing but at least works:

val props = Properties().apply {
    load(FileInputStream(File(rootProject.rootDir, "versions.properties")))
}
dependencyManagement {
    imports {
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${props.getProperty("version.org.springframework.cloud..spring-cloud-dependencies")}")
    }
}
pavelbrylov commented 3 months ago

@LouisCAD Is there a chance there will be support for BOM versions? We are using the approach suggested by @Flowkap above, but the versions for the BOMs aren't being updated by the plugin this way, so one still has to manually check if there are updates for the BOMs... Maybe there is a better way to use both BOMs and refreshVersions plugin? Thanks!

LouisCAD commented 3 months ago

Hello, the way to go is:

dependencies {
    implementation(platform("whatever:the.bom:_"))
    implementation("whatever:something")
}