gradle-versions-plugin icon indicating copy to clipboard operation
gradle-versions-plugin copied to clipboard

platform + runtimeOnly = failed to compare

Open alamothe opened this issue 2 years ago • 4 comments

Hello, I have a platform subproject:

plugins {
	id("java-platform")
}

dependencies {
	constraints {
		// ...
		api("mysql:mysql-connector-java:8.0.27")
	}
}

And then another subproject:

plugins {
	id("com.github.ben-manes.versions")
}

dependencies {
	api(platform(project(":platform")))

	runtimeOnly("mysql:mysql-connector-java")
}

The output is:

Failed to compare versions for the following dependencies because they were declared without version:
 - mysql:mysql-connector-java

All other combinations seem to work without problems. Only platform + runtimeOnly fails in this way. Any suggestions?

alamothe avatar Oct 31 '21 00:10 alamothe

I'm not familiar with dependency constraints, but there was a contribution that checks them. Does that help?

Constraints

If you use constraints, for example to define a BOM using the java-platform plugin or to manage transitive dependency versions, you can enable checking of constraints by specifying the checkConstraints attribute of the dependencyUpdates task.

tasks.named("dependencyUpdates").configure {
  checkConstraints = true
}

ben-manes avatar Oct 31 '21 00:10 ben-manes

My bad, I forgot to mention that I did set that option:

configure(subprojects.filter {
	it.name != "platform"
}) {
	apply(plugin = "org.jetbrains.kotlin.jvm")
	apply(plugin = "com.github.ben-manes.versions")

	repositories {
		mavenCentral()
	}

	tasks.named<DependencyUpdatesTask>("dependencyUpdates") {
		revision = "release"
		checkConstraints = true

		rejectVersionIf {
			candidate.version.contains("(rc|RC|M1|alpha|beta)".toRegex())
		}
	}
}

If I change from runtimeOnly to implementation it will work:

plugins {
	id("com.github.ben-manes.versions")
}

dependencies {
	api(platform(project(":platform")))

	implementation("mysql:mysql-connector-java")
}

It will also work if I specify a version in runtimeOnly. So the only combination that doesn't work is platform + runtimeOnly.

alamothe avatar Oct 31 '21 01:10 alamothe

That's strange since we don't treat configurations differently and simply iterate over all that are resolvable. You are welcome to investigate to figure out the root cause (see Resolver). This is one of those cases of reverse engineering the Gradle APIs to determine what it does and why. I'd recommend reproducing in a minimal project to simplify iterations, if you're inclined to debug this.

ben-manes avatar Oct 31 '21 01:10 ben-manes

I know why it happened. It is actually Gradle stuff. The runtimeOnly configuration is not extended from api, see this diagram

So you should put runtimeOnly(platform(project(":platform"))) if you want runtimeOnly configuration to pick up your java-platform

Btw, similar story if you applied annotationProcessor + platform. In fact, I doubt that you would want to write xxx(platform(project(":platform"))) where xxx are all the configuration that are not extended from api configuration.

CXwudi avatar Nov 16 '22 07:11 CXwudi