Skip to content

Conversation

wolfs
Copy link
Member

@wolfs wolfs commented Apr 5, 2022

This PRs explores what would be necessary to compile build scripts against a different Gradle API. It allows passing the Gradle API version via -Dorg.gradle.api.version=6.9 to the Gradle installation. Note that you also need a repository which contains an artifact for the Gradle API of this version with the coordinates org.gradle:gradle-api:<version>. You can specify the URL of the repository via -Dgradle.api.repository.url=....

Currently this works for Kotlin and Groovy build scripts. It also should work for Kotlin pre-compiled scripts and Kotlin and Groovy build logic. Though it doesn't work for Groovy pre-compiled build scripts. I suppose we should be able to make this work with Groovy pre-compiled build scripts as well, though I did run into some classloader problems there.

You can also declare a dependency in your build script on the Gradle API with a version by using gradleApi(<version>) instead of gradleApi().

Exploration doc: https://docs.google.com/document/d/1JB75X_Lt5BlubszqD0l10rHPqL89B2yd-yD39qizyDA/edit

@wolfs wolfs self-assigned this Apr 5, 2022
@wolfs wolfs force-pushed the wolfs/provider/compile-groovy-scripts-against-gradle-api branch from 1cb5d97 to aa9a6be Compare April 5, 2022 12:17
@wolfs wolfs force-pushed the wolfs/provider/compile-groovy-scripts-against-gradle-api branch from aa9a6be to 600bab3 Compare April 5, 2022 12:18
/**
* Creates a dependency on the API of the current version of Gradle.
*
* @return The dependency.
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to add some Javadoc on the expected format of the parameter. Are snapshots accepted?

I think we need to mention that only older versions are accepted, right? What happens if I give it a newer or non-existent version?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, probably. Though I wouldn't go into polishing the Javadoc for this spike.

return new GroovyScriptClasspathProvider(
classLoaderScopeRegistry.getCoreAndPluginsScope(),
() -> {
String version = System.getProperty("org.gradle.api.version");
Copy link
Member

Choose a reason for hiding this comment

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

We should qualify what API version this is. I'd go with org.gradle.api.target-version or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think we should qualify the property name. It feels like target doesn't really capture it. For me, target sounds more about the target runtime. How about org.gradle.api.source-version, since this is the version of the Gradle API we use for sources.

Copy link
Member Author