Search in sources :

Example 1 with ScalaSourceDirectorySet

use of org.gradle.api.tasks.ScalaSourceDirectorySet in project gradle by gradle.

the class DefaultScalaSourceSet method createScalaSourceDirectorySet.

private static ScalaSourceDirectorySet createScalaSourceDirectorySet(String name, String displayName, ObjectFactory objectFactory) {
    ScalaSourceDirectorySet scalaSourceDirectorySet = new DefaultScalaSourceDirectorySet(objectFactory.sourceDirectorySet(name, displayName));
    scalaSourceDirectorySet.getFilter().include("**/*.java", "**/*.scala");
    return scalaSourceDirectorySet;
}
Also used : ScalaSourceDirectorySet(org.gradle.api.tasks.ScalaSourceDirectorySet)

Example 2 with ScalaSourceDirectorySet

use of org.gradle.api.tasks.ScalaSourceDirectorySet 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);
        }
    });
}
Also used : IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) Task(org.gradle.api.Task) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) Transformer(org.gradle.api.Transformer) ArtifactView(org.gradle.api.artifacts.ArtifactView) ScalaSourceDirectorySet(org.gradle.api.tasks.ScalaSourceDirectorySet) Jar(org.gradle.jvm.tasks.Jar)

Aggregations

ScalaSourceDirectorySet (org.gradle.api.tasks.ScalaSourceDirectorySet)2 Task (org.gradle.api.Task)1 Transformer (org.gradle.api.Transformer)1 ArtifactView (org.gradle.api.artifacts.ArtifactView)1 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)1 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)1 Jar (org.gradle.jvm.tasks.Jar)1