use of org.gradle.api.tasks.scala.ScalaCompile in project gradle by gradle.
the class ScalaBasePlugin method configureScalaCompile.
private static void configureScalaCompile(final Project project, final SourceSet sourceSet) {
String taskName = sourceSet.getCompileTaskName("scala");
final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
SourceSetUtil.configureForSourceSet(sourceSet, scalaSourceSet.getScala(), scalaCompile, scalaCompile.getOptions(), project);
scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
scalaCompile.setSource(scalaSourceSet.getScala());
project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);
// cannot use convention mapping because the resulting object won't be serializable
// cannot compute at task execution time because we need association with source set
project.getGradle().addBuildListener(new BuildAdapter() {
@Override
public void projectsEvaluated(Gradle gradle) {
IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
if (incrementalOptions.getAnalysisFile() == null) {
String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
incrementalOptions.setAnalysisFile(new File(analysisFilePath));
}
if (incrementalOptions.getPublishedCode() == null) {
Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
}
}
});
}
use of org.gradle.api.tasks.scala.ScalaCompile in project gradle by gradle.
the class ScalaBasePlugin method configureScalaCompile.
private static void configureScalaCompile(final Project project, JavaBasePlugin javaPlugin, final SourceSet sourceSet) {
String taskName = sourceSet.getCompileTaskName("scala");
final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
javaPlugin.configureForSourceSet(sourceSet, scalaCompile);
Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
scalaCompile.setSource(scalaSourceSet.getScala());
project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);
// cannot use convention mapping because the resulting object won't be serializable
// cannot compute at task execution time because we need association with source set
project.getGradle().addBuildListener(new BuildAdapter() {
@Override
public void projectsEvaluated(Gradle gradle) {
IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
if (incrementalOptions.getAnalysisFile() == null) {
String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
incrementalOptions.setAnalysisFile(new File(analysisFilePath));
}
if (incrementalOptions.getPublishedCode() == null) {
Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
}
}
});
}
use of org.gradle.api.tasks.scala.ScalaCompile in project gradle by gradle.
the class ScalaBasePlugin method configureScalaCompile.
@SuppressWarnings("deprecation")
private void configureScalaCompile(final Project project, final SourceSet sourceSet, final Configuration incrementalAnalysis, final Usage incrementalAnalysisUsage, final ScalaRuntime scalaRuntime) {
final ScalaSourceDirectorySet scalaSourceSet = sourceSet.getExtensions().getByType(ScalaSourceDirectorySet.class);
final TaskProvider<ScalaCompile> scalaCompileTask = project.getTasks().register(sourceSet.getCompileTaskName("scala"), ScalaCompile.class, scalaCompile -> {
JvmPluginsHelper.configureForSourceSet(sourceSet, scalaSourceSet, scalaCompile, scalaCompile.getOptions(), project);
scalaCompile.setDescription("Compiles the " + scalaSourceSet + ".");
scalaCompile.setSource(scalaSourceSet);
scalaCompile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
scalaCompile.getAnalysisMappingFile().set(project.getLayout().getBuildDirectory().file("tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".mapping"));
// cannot compute at task execution time because we need association with source set
IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
incrementalOptions.getAnalysisFile().set(project.getLayout().getBuildDirectory().file("tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis"));
incrementalOptions.getClassfileBackupDir().set(project.getLayout().getBuildDirectory().file("tmp/scala/classfileBackup/" + scalaCompile.getName() + ".bak"));
final Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
if (jarTask != null) {
incrementalOptions.getPublishedCode().set(jarTask.getArchiveFile());
}
scalaCompile.getAnalysisFiles().from(incrementalAnalysis.getIncoming().artifactView(new Action<ArtifactView.ViewConfiguration>() {
@Override
public void execute(ArtifactView.ViewConfiguration viewConfiguration) {
viewConfiguration.lenient(true);
viewConfiguration.componentFilter(new IsProjectComponent());
}
}).getFiles());
// See https://github.com/gradle/gradle/issues/14434. We do this so that the incrementalScalaAnalysisForXXX configuration
// is resolved during task graph calculation. It is not an input, but if we leave it to be resolved during task execution,
// it can potentially block trying to resolve project dependencies.
scalaCompile.dependsOn(scalaCompile.getAnalysisFiles());
});
JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, scalaSourceSet, project, scalaCompileTask, scalaCompileTask.map(new Transformer<CompileOptions, ScalaCompile>() {
@Override
public CompileOptions transform(ScalaCompile scalaCompile) {
return scalaCompile.getOptions();
}
}));
project.getTasks().named(sourceSet.getClassesTaskName(), new Action<Task>() {
@Override
public void execute(Task task) {
task.dependsOn(scalaCompileTask);
}
});
}
Aggregations