Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accessibility to the Gradle runtime compatibility from within toolbox infrastructure #112

Open
wants to merge 5 commits into
base: develop-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions subprojects/gradle-plugin-development/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import static dev.gradleplugins.GradleRuntimeCompatibility.*

plugins {
id 'org.jetbrains.kotlin.jvm' version "1.3.72"
id 'toolboxbuild.publish'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ abstract class AbstractGradlePluginDevelopmentUnitTestingFunctionalTest extends
mavenCentral()
}

import static ${GradleRuntimeCompatibility.canonicalName}.groovyVersionOf
import ${GradleVersion.canonicalName}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package dev.gradleplugins;

import org.gradle.api.JavaVersion;
import org.gradle.api.Project;
import org.gradle.api.provider.Provider;
import org.gradle.util.GradleVersion;

/**
* Gradle extension to access Gradle runtime information such as packaged version of Groovy and Kotlin.
* <p>
* All method takes a Gradle version in either of the following forms:
* <ul>
* <li>{@link GradleVersion}: a Gradle version instance</li>
* <li>String: any String parsable by {@link GradleVersion#version(String)}</li>
* <li>{@link Provider} to any supported types</li>
* <li>{@link Object#toString()} for any other instance</li>
* </ul>
*/
public interface GradleRuntimeCompatibilitiesExtension {
/**
* Returns the Groovy version packaged with the specified Gradle version.
*
* @param gradleVersion a specific Gradle version
* @return the Groovy version of the specified Gradle version, never null.
*/
Provider<String> groovyVersionOf(Object gradleVersion);

/**
* Returns the minimum Java version of the specified Gradle version.
*
* @param gradleVersion a specific Gradle version
* @return the minimum Java version for the specified Gradle version, never null.
*/
Provider<JavaVersion> minimumJavaVersionFor(Object gradleVersion);

/**
* Returns the Kotlin version packaged with the specified Gradle version.
* All Gradle version without Kotlin DSL support will return an empty value.
*
* @param gradleVersion a specific Gradle version
* @return the Kotlin version for the specified Gradle version, never null.
*/
Provider<String> kotlinVersionOf(Object gradleVersion);

/**
* Returns the last patched Gradle version for the specified Gradle version.
* For example, passing Gradle version {@literal 6.2} would return {@literal 6.2.2}, the last patched version of {@literal 6.2.x}.
*
* @param gradleVersion the Gradle version to find the last patched version, must not be null.
* @return the latest patched version for the specified version, never null
*/
Provider<GradleVersion> lastPatchedVersionOf(Object gradleVersion);

/**
* Returns the last minor released Gradle version for the specified major Gradle version.
* For example, passing Gradle version {@literal 7.3} would return {@literal 7.6.4}, the last minor release of {@literal 7.x}.
* The function will return the last patched version as well.
*
* @param gradleVersion the Gradle version to find the last minor release for, must not be null
* @return the latest minor version for the specified version, never null
*/
Provider<GradleVersion> lastMinorReleaseOf(Object gradleVersion);

/**
* Returns the extension for this project.
* The user must apply one of the following plugins: {@literal dev.gradleplugins.gradle-plugin-base} or {@literal dev.gradleplugins.gradle-plugin-development}.
*
* @param project the project to get the extension
* @return the extension, never null
*/
static GradleRuntimeCompatibilitiesExtension forProject(Project project) {
assert project != null : "'project' must not be null";
return project.getExtensions().getByType(GradleRuntimeCompatibilitiesExtension.class);
}
}
Loading
Loading