Class SharedUtil
- Implementation Note:
- Consumers should make their own
Utilclass and extend this one with it to inherit all static methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidensureAfterEvaluate(Project project, Closure<?> closure) Runs the given closure usingProject.afterEvaluate(Action).static voidensureAfterEvaluate(Project project, Action<? super Project> action) Runs the given action usingProject.afterEvaluate(Action).Makes a returning-self closure that finalizes a given property usingfinalizeProperty(Property).static <P extends Property<?>>
PfinalizeProperty(P property) Finalizes the given property to prevent any additional changes from being made to it.static Provider<JavaLauncher> launcherFor(JavaPluginExtension java, JavaToolchainService javaToolchains, int version) Gets the Java launcher that can compile or run the given version.static Provider<JavaLauncher> launcherFor(JavaPluginExtension java, JavaToolchainService javaToolchains, JavaLanguageVersion version) Gets the Java launcher that can compile or run the given version.static Provider<JavaLauncher> launcherFor(Project project, int version) Gets the Java launcher that can compile or run the given version.static Provider<JavaLauncher> launcherFor(Project project, JavaLanguageVersion version) Gets the Java launcher that can compile or run the given version.static Provider<JavaLauncher> launcherFor(Provider<? extends JavaPluginExtension> java, Provider<? extends JavaToolchainService> javaToolchains, int version) Gets the Java launcher that can compile or run the given version.static Provider<JavaLauncher> launcherFor(Provider<? extends JavaPluginExtension> java, Provider<? extends JavaToolchainService> javaToolchains, JavaLanguageVersion version) Gets the Java launcher that can compile or run the given version.static Provider<JavaLauncher> launcherForStrictly(Project project, int version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.static Provider<JavaLauncher> launcherForStrictly(Project project, JavaLanguageVersion version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.static Provider<JavaLauncher> launcherForStrictly(Provider<? extends JavaToolchainService> javaToolchains, int version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.static Provider<JavaLauncher> launcherForStrictly(Provider<? extends JavaToolchainService> javaToolchains, JavaLanguageVersion version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.static Provider<JavaLauncher> launcherForStrictly(JavaToolchainService javaToolchains, int version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.static Provider<JavaLauncher> launcherForStrictly(JavaToolchainService javaToolchains, JavaLanguageVersion version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.static OutputStreamCreates an output stream that logs to the given action.static StringtoString(Dependency dependency) Converts a given dependency to string.static StringtoString(ModuleVersionSelector module) Converts a given module to string.
-
Constructor Details
-
SharedUtil
protected SharedUtil()Empty constructor. This class should only be extended to make referencing these static methods easier.
-
-
Method Details
-
launcherFor
public static Provider<JavaLauncher> launcherFor(JavaPluginExtension java, JavaToolchainService javaToolchains, int version) Gets the Java launcher that can compile or run the given version.
If the currently running Java toolchain is able to compile and run the given version, it will be used instead.
- Parameters:
java- The Java plugin extension of the currently-used toolchainjavaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherFor
public static Provider<JavaLauncher> launcherFor(JavaPluginExtension java, JavaToolchainService javaToolchains, JavaLanguageVersion version) Gets the Java launcher that can compile or run the given version.
If the currently running Java toolchain is able to compile and run the given version, it will be used instead.
- Parameters:
java- The Java plugin extension of the currently-used toolchainjavaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherFor
public static Provider<JavaLauncher> launcherFor(Provider<? extends JavaPluginExtension> java, Provider<? extends JavaToolchainService> javaToolchains, int version) Gets the Java launcher that can compile or run the given version.
If the currently running Java toolchain is able to compile and run the given version, it will be used instead.
- Parameters:
java- The Java plugin extension of the currently-used toolchainjavaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherFor
public static Provider<JavaLauncher> launcherFor(Provider<? extends JavaPluginExtension> java, Provider<? extends JavaToolchainService> javaToolchains, JavaLanguageVersion version) Gets the Java launcher that can compile or run the given version.
If the currently running Java toolchain is able to compile and run the given version, it will be used instead.
- Parameters:
java- The Java plugin extension of the currently-used toolchainjavaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherFor
Gets the Java launcher that can compile or run the given version.
If the currently running Java toolchain is able to compile and run the given version, it will be used instead.
- Parameters:
project- The project to get the Java extensions fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherFor
Gets the Java launcher that can compile or run the given version.
If the currently running Java toolchain is able to compile and run the given version, it will be used instead.
- Parameters:
project- The project to get the Java extensions fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherForStrictly
public static Provider<JavaLauncher> launcherForStrictly(JavaToolchainService javaToolchains, int version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.- Parameters:
javaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherForStrictly
public static Provider<JavaLauncher> launcherForStrictly(JavaToolchainService javaToolchains, JavaLanguageVersion version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.- Parameters:
javaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherForStrictly
public static Provider<JavaLauncher> launcherForStrictly(Provider<? extends JavaToolchainService> javaToolchains, int version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.- Parameters:
javaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherForStrictly
public static Provider<JavaLauncher> launcherForStrictly(Provider<? extends JavaToolchainService> javaToolchains, JavaLanguageVersion version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.- Parameters:
javaToolchains- The Java toolchain service to get the Java launcher fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherForStrictly
Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.- Parameters:
project- The extension-aware object to get the Java extensions fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
launcherForStrictly
public static Provider<JavaLauncher> launcherForStrictly(Project project, JavaLanguageVersion version) Gets the Java launcher strictly for the given version, even if the currently running Java toolchain is higher than it.- Parameters:
project- The extension-aware object to get the Java extensions fromversion- The version of Java required- Returns:
- A provider for the Java launcher
-
ensureAfterEvaluate
public static void ensureAfterEvaluate(Project project, @DelegatesTo(value=Project.class,strategy=1) Closure<?> closure) Runs the given closure usingProject.afterEvaluate(Action). If the project is already executed, the closure will be called instantly.- Parameters:
project- The project to run the closure onclosure- The closure to execute
-
ensureAfterEvaluate
Runs the given action usingProject.afterEvaluate(Action). If the project is already executed, the action will be executed instantly.- Parameters:
project- The project to run the action onaction- The action to execute
-
toLog
Creates an output stream that logs to the given action.- Parameters:
logger- The logger to log to- Returns:
- The output stream
-
toString
Converts a given module to string. Use this instead ofObject.toString().- Parameters:
module- The module- Returns:
- The string representation
-
toString
Converts a given dependency to string. Use this instead ofObject.toString().- Parameters:
dependency- The dependency- Returns:
- The string representation
-
finalizeProperty
Makes a returning-self closure that finalizes a given property using
finalizeProperty(Property).This is best used as the method argument for org.codehaus.groovy.runtime.DefaultGroovyMethods#tap(Object, Closure), which allows for in-lining property creation in Groovy code.
- Type Parameters:
P- The type of property to finalize- Returns:
- The returning-self closure for finalizing a property
-
finalizeProperty
@Contract(value="_ -> param1", mutates="param1") public static <P extends Property<?>> P finalizeProperty(P property) Finalizes the given property to prevent any additional changes from being made to it.
This is done by simply calling
HasConfigurableValue.disallowChanges()andHasConfigurableValue.finalizeValueOnRead(). These methods do not return the object itself, so this helper method exists to in-line property creation without needing to reference it again just to call these methods.- Type Parameters:
P- The type of property to finalize- Parameters:
property- The property to finalize- Returns:
- The property
-