Skip to content

Commit

Permalink
gradle task configuration avoidance
Browse files Browse the repository at this point in the history
also fix an issue in BaselineJavaVersion
  • Loading branch information
rzpt committed Jun 11, 2022
1 parent e09ca93 commit 0d359bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ class BaselineEclipse extends AbstractBaselinePlugin {
}

// Run eclipseTemplate when eclipse task is run
project.tasks.eclipse.dependsOn(eclipseTemplate)
project.tasks.named("eclipse").configure {
dependsOn(eclipseTemplate)
}

// Override default Eclipse JRE.
project.tasks.eclipseClasspath.doFirst {
String eclipseClassPath = "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-" + project.sourceCompatibility;
project.eclipse.classpath {
containers.clear()
containers.add(eclipseClassPath)
project.tasks.named("eclipseClasspath").configure {
doFirst {
String eclipseClassPath = "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-" + project.sourceCompatibility;
project.eclipse.classpath {
containers.clear()
containers.add(eclipseClassPath)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class BaselineIdea extends AbstractBaselinePlugin {
}
}

project.getTasks().findByName("idea").doLast(cleanup)
project.getTasks().named("idea").configure(idea -> idea.doLast(cleanup))
}

void applyToRootProject(Project rootProject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ public void apply(Project project) {
project.getExtensions().getByType(SourceSetContainer.class).configureEach(sourceSet -> {
project.getTasks()
.named(sourceSet.getCompileJavaTaskName(), JavaCompile.class)
.get()
.getOptions()
.getCompilerArgumentProviders()
// Use an anonymous class because tasks with lambda inputs cannot be cached
.add(new CommandLineArgumentProvider() {
@Override
public Iterable<String> asArguments() {
if (hasImmutablesProcessor(project, sourceSet)) {
return Collections.singletonList("-Aimmutables.gradle.incremental");
}
.configure(javaCompileTask -> {
javaCompileTask
.getOptions()
.getCompilerArgumentProviders()
// Use an anonymous class because tasks with lambda inputs cannot be cached
.add(new CommandLineArgumentProvider() {
@Override
public Iterable<String> asArguments() {
if (hasImmutablesProcessor(project, sourceSet)) {
return Collections.singletonList("-Aimmutables.gradle.incremental");
}

return Collections.emptyList();
}
return Collections.emptyList();
}
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.GroovyCompile;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
Expand Down Expand Up @@ -71,15 +72,15 @@ public void execute(JavaToolchainSpec javaToolchainSpec) {
configureExecutionTasks(project, javaToolchains.forVersion(extension.runtime()));

// Validation
project.getTasks()
TaskProvider<CheckJavaVersionsTask> checkJavaVersions = project.getTasks()
.register("checkJavaVersions", CheckJavaVersionsTask.class, new Action<CheckJavaVersionsTask>() {
@Override
public void execute(CheckJavaVersionsTask task) {
task.getTargetVersion().set(extension.target());
task.getRuntimeVersion().set(extension.runtime());
project.getTasks().getByName("check").dependsOn(task);
}
});
project.getTasks().named("check").configure(check -> check.dependsOn(checkJavaVersions));
});
}

Expand Down

0 comments on commit 0d359bd

Please sign in to comment.