refreshVersions icon indicating copy to clipboard operation
refreshVersions copied to clipboard

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

Open juherr opened this issue 3 years ago • 5 comments

🐛 Describe the bug

Spring boot project doesn't compile after refreshVersions migration task.

⚠️ 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

juherr avatar May 30 '22 12:05 juherr

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

toddobryan avatar Aug 16 '22 21:08 toddobryan

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 avatar Feb 07 '23 09:02 Flowkap

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")}")
    }
}

Flowkap avatar Feb 24 '23 10:02 Flowkap