An annotation to easily make Gradle Tasks use the Worker API, which is required for Gradle tasks to run in parallel within the same project.
Add the library as an annotation processor:
dependencies {
compileOnly 'com.palantir.gradle.auto-parallelizable:auto-parallelizable-annotations'
annotationProcessor 'com.palantir.gradle.auto-parallelizable:auto-parallelizable'
}
Reload Gradle in IntelliJ.
Now you can write a container class that will generate the required files:
@AutoParallelizable
final class MyCustom {
// Create a package-private Params interface with you task
// inputs/outputs as Gradle Managed Properties
interface Params {
@Input
Property<String> getString();
@OutputFile
RegularFileProperty getOutput();
}
// Create a package-private static void action method here
static void action(Params params) {
// do your task action here
}
private MyCustom() {}
}
Then implement a task next to this:
public abstract class MyCustomTask extends MyCustomTaskImpl {
public MyCustomTask() {
// You can initialize values, description etc here
getString().set("default value");
}
}
Compile your code and the files MyCustomTaskImpl
, MyCustomWorkParams
, MyCustomWorkAction
will be generated for you!
You can inject Gradle Services into your action
method like so:
import com.palantir.gradle.autoparallelizable.AutoParallelizable.Inject;
@AutoParallelizable
final class MyCustom {
// Params etc ...
static void action(
Params params,
@Inject ExecOperations execOperations,
@Inject ProviderFactory providerFactory) {
// Use your injected services here!
}
}
You can use Read-only managed nested properties
in your Params
interface. Properties will be recursively set.
@AutoParallelizable
final class MyCustom {
interface Nested {
@Input
Property<String> getString();
}
interface DoubleNested {
Property<String> getDescription();
@Nested
Nested getNested();
}
interface Params {
@Nested
Nested getNested();
@Nested
DoubleNested getDoubleNested();
@Nested
ListProperty<Nested> getNestedList();
@OutputFile
RegularFileProperty getOutput();
}
// action etc ...
private MyCustom() {}
}
Note: If you are using a nested type you don't own, bear in mind that you will need to recompile against newer versions to have any new properties copied over.