private void createCompileJavaTaskForBinary(final SourceSet sourceSet, SourceDirectorySet javaSourceSet, Project target) { JavaCompile compileTask = target.getTasks().create(sourceSet.getCompileJavaTaskName(), JavaCompile.class); compileTask.setDescription("Compiles " + javaSourceSet + "."); compileTask.setSource(javaSourceSet); ConventionMapping conventionMapping = compileTask.getConventionMapping(); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getOutput().getClassesDir(); } }); }
private void configureCompileTestJavaTask(final Project project) { final JavaCompile compileTestJava = (JavaCompile) project.getTasks() .findByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME); final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test"); final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME); compileTestJava.getInputs().property("moduleName", module.geName()); compileTestJava.doFirst(new Action<Task>() { @Override public void execute(Task task) { List<String> args = new ArrayList<>(); args.add("--module-path"); args.add(compileTestJava.getClasspath().getAsPath()); args.add("--add-modules"); args.add("junit"); args.add("--add-reads"); args.add(module.geName() + "=junit"); args.add("--patch-module"); args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath()); compileTestJava.getOptions().setCompilerArgs(args); compileTestJava.setClasspath(project.files()); } }); }
/** * Creates the tasks to build unit tests. */ public void createUnitTestVariantTasks( @NonNull TaskFactory tasks, @NonNull TestVariantData variantData) { variantData.assembleVariantTask.dependsOn(createMockableJar); VariantScope variantScope = variantData.getScope(); createPreBuildTasks(tasks, variantScope); createProcessJavaResTask(tasks, variantScope); createCompileAnchorTask(tasks, variantScope); AndroidTask<JavaCompile> javacTask = createJavacTask(tasks, variantScope); setJavaCompilerTask(javacTask, tasks, variantScope); createUnitTestTask(tasks, variantData); // This hides the assemble unit test task from the task list. variantData.assembleVariantTask.setGroup(null); }
@Nullable @Override public URL apply(@Nullable JavaCompile task) { checkNotNull(task); final File destDir = task.getDestinationDir(); if (destDir == null) { return null; } final URI destUri = destDir.toURI(); try { final URL destUrl = destUri.toURL(); return destUrl; } catch (MalformedURLException e) { throw new IllegalArgumentException(format( "Could not retrieve destination directory for task `%s`.", task.getName()), e); } }
private List<String> buildCompilerArgs(JavaPluginConvention javaPluginConvention) { TaskCollection<JavaCompile> javaCompilers = getProject().getTasks().withType(JavaCompile.class); CompileOptions firstCompilerOptions = javaCompilers.isEmpty() ? null : javaCompilers.iterator().next().getOptions(); List<String> args = new ArrayList<>(Arrays.asList("-source", javaPluginConvention.getSourceCompatibility().toString(), "-target", javaPluginConvention.getTargetCompatibility().toString(), "-encoding", getDefaultOrCompilerEncoding(firstCompilerOptions))); if (firstCompilerOptions != null) { FileCollection bootClasspath = firstCompilerOptions.getBootstrapClasspath(); if (bootClasspath != null) { args.add("-bootclasspath"); args.add(bootClasspath.getAsPath()); } } return args; }
@TaskAction public void run() { TaskCollection<JavaCompile> javaCompileTasks = this.getProject().getTasks().withType(JavaCompile.class); CompilerInputOutputConfiguration inputOutputDirectories = new JavaccCompilerInputOutputConfiguration(getInputDirectory(), getOutputDirectory(), getSource(), javaCompileTasks); JjtreeProgramInvoker jjtreeInvoker = new JjtreeProgramInvoker(getProject(), getClasspath(), inputOutputDirectories.getTempOutputDirectory()); ProgramArguments arguments = new ProgramArguments(); arguments.addAll(getArguments()); SourceFileCompiler compiler = new JavaccSourceFileCompiler(jjtreeInvoker, arguments, inputOutputDirectories, getLogger()); compiler.createTempOutputDirectory(); compiler.compileSourceFilesToTempOutputDirectory(); compiler.copyCompiledFilesFromTempOutputDirectoryToOutputDirectory(); compiler.copyNonJavaccFilesToOutputDirectory(); compiler.cleanTempOutputDirectory(); }
@TaskAction public void run() { TaskCollection<JavaCompile> javaCompileTasks = this.getProject().getTasks().withType(JavaCompile.class); CompilerInputOutputConfiguration inputOutputDirectories = new JavaccCompilerInputOutputConfiguration(getInputDirectory(), getOutputDirectory(), getSource(), javaCompileTasks); JavaccProgramInvoker javaccInvoker = new JavaccProgramInvoker(getProject(), getClasspath(), inputOutputDirectories.getTempOutputDirectory()); ProgramArguments arguments = new ProgramArguments(); arguments.addAll(getArguments()); SourceFileCompiler compiler = new JavaccSourceFileCompiler(javaccInvoker, arguments, inputOutputDirectories, getLogger()); compiler.createTempOutputDirectory(); compiler.compileSourceFilesToTempOutputDirectory(); compiler.copyCompiledFilesFromTempOutputDirectoryToOutputDirectory(); compiler.copyNonJavaccFilesToOutputDirectory(); compiler.cleanTempOutputDirectory(); }
@Test public void generatedJavaFilesFromCompileJavaccAreAddedToMainJavaSourceSet() { applyJavaccPluginToProject(); applyJavaPluginToProject(); JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction(); final File outputDirectory = new File(getClass().getResource("/javacc/testgenerated").getFile()); CompileJavaccTask compileJavaccTask = (CompileJavaccTask) project.getTasks().findByName(CompileJavaccTask.TASK_NAME_VALUE); compileJavaccTask.setOutputDirectory(outputDirectory); action.execute(project); TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class); for (JavaCompile task : javaCompilationTasks) { assertTrue(task.getSource().contains(new File(outputDirectory, "someSourceFile.txt"))); } }
@Test public void getJavaSourceTreeReturnsAggregatedJavaCompileSourceWhenMultipleJavaCompileTasks() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class); testFolder.newFolder("inputTest"); File testFile = addTaskWithSourceFile(project, "compileTest", "inputTest/AnotherTestClass.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, containsInAnyOrder(javaFile.getCanonicalFile(), testFile.getCanonicalFile())); }
@Test public void getJavaSourceTreeExcludesOutputFolder() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class); File outputFile = addTaskWithSourceFile(project, "compileJavaccGenerated", "output/Generated.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, contains(javaFile.getCanonicalFile())); assertThat(javaSourceTree, not(contains(outputFile.getCanonicalFile()))); }
@Test public void getCompleteSourceTreeReturnsSourceAndJavaSourceWhenProjectHasJavaCompileTasks() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class); testFolder.newFolder("inputJava"); File javaFile = addTaskWithSourceFile(project, "compileJava", "inputJava/MyClass.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource()) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree completeSourceTree = configuration.getCompleteSourceTree(); assertThat(completeSourceTree, containsInAnyOrder(javaccFile.getCanonicalFile(), javaFile.getCanonicalFile())); }
@Test public void getCompleteSourceTreeExcludesOutputFolder() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class); File outputFile = addTaskWithSourceFile(project, "compileJavaccGenerated", "output/Generated.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource()) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree completeSourceTree = configuration.getCompleteSourceTree(); assertThat(completeSourceTree, contains(javaccFile.getCanonicalFile())); assertThat(completeSourceTree, not(contains(outputFile.getCanonicalFile()))); }
private void configureCompileJavaTask(final Project project) { final JavaCompile compileJava = (JavaCompile) project.getTasks().findByName(JavaPlugin.COMPILE_JAVA_TASK_NAME); compileJava.doFirst(new Action<Task>() { @Override public void execute(Task task) { List<String> args = new ArrayList<>(); args.add("--module-path"); args.add(compileJava.getClasspath().getAsPath()); compileJava.getOptions().setCompilerArgs(args); compileJava.setClasspath(project.files()); } }); }
@Override public void apply(Project project) { project.getExtensions().create("springBoot", SpringBootPluginExtension.class, project); project.getPlugins().apply(JavaPlugin.class); new AgentPluginFeatures().apply(project); new RepackagePluginFeatures().apply(project); new RunPluginFeatures().apply(project); new DependencyManagementPluginFeatures().apply(project); project.getTasks().withType(JavaCompile.class).all(new SetUtf8EncodingAction()); }
@Override public void execute(final JavaCompile compile) { compile.doFirst(new Action<Task>() { @Override @SuppressWarnings("deprecation") public void execute(Task t) { if (compile.getOptions().getEncoding() == null) { compile.getOptions().setEncoding("UTF-8"); } } }); }
private void setupFeaturesSource(final Project project, final ApplicationVariant applicationVariant) { final JavaCompile javaCompile = applicationVariant.getJavaCompile(); javaCompile.doFirst(new Action<Task>() { @Override public void execute(Task task) { writeFeatureFile(project, applicationVariant); } }); }
private static URLClassLoader createClassLoaderForProject(Project project) { final Collection<JavaCompile> tasks = allJavaCompile(project); final URL[] compiledCodePath = extractDestinationDirs(tasks); log().debug("Initializing ClassLoader for URLs: {}", deepToString(compiledCodePath)); try { @SuppressWarnings("ClassLoaderInstantiation") // Caught exception. final URLClassLoader result = new URLClassLoader(compiledCodePath, ModelVerifier.class.getClassLoader()); return result; } catch (SecurityException e) { throw new IllegalStateException("Cannot analyze project source code.", e); } }
@Test public void retrieve_compilation_dest_dir_from_task() throws MalformedURLException { final JavaCompile compileTask = actualProject().getTasks() .withType(JavaCompile.class) .getByName(COMPILE_JAVA.getValue()); final File dest = Files.createTempDir(); compileTask.setDestinationDir(dest); final Function<JavaCompile, URL> func = ModelVerifier.GetDestinationDir.FUNCTION; final URL destUrl = dest.toURI().toURL(); assertEquals(destUrl, func.apply(compileTask)); }
@Override public void apply(Project project) { project.getExtensions().create("springBoot", SpringBootPluginExtension.class); project.getPlugins().apply(JavaPlugin.class); new AgentPluginFeatures().apply(project); new RepackagePluginFeatures().apply(project); new RunPluginFeatures().apply(project); new DependencyManagementPluginFeatures().apply(project); project.getTasks().withType(JavaCompile.class).all(new SetUtf8EncodingAction()); }
private void createCompileJavaTaskForBinary(final ClassDirectoryBinarySpecInternal binary, final Project target) { final BinaryNamingScheme namingScheme = binary.getNamingScheme(); binary.getSource().withType(JavaSourceSet.class).all(new Action<JavaSourceSet>() { public void execute(JavaSourceSet javaSourceSet) { JavaCompile compileTask = target.getTasks().create(namingScheme.getTaskName("compile", "java"), JavaCompile.class); configureCompileTask(compileTask, javaSourceSet, binary); binary.getTasks().add(compileTask); binary.builtBy(compileTask); } }); }
public void apply(final Project target) { target.getPlugins().apply(JvmLanguagePlugin.class); BinaryContainer jvmBinaryContainer = target.getExtensions().getByType(BinaryContainer.class); jvmBinaryContainer.withType(ClassDirectoryBinary.class).all(new Action<ClassDirectoryBinary>() { public void execute(final ClassDirectoryBinary binary) { final BinaryNamingScheme namingScheme = ((BinaryInternal) binary).getNamingScheme(); binary.getSource().withType(JavaSourceSet.class).all(new Action<JavaSourceSet>() { public void execute(JavaSourceSet javaSourceSet) { // TODO: handle case where binary has multiple JavaSourceSet's JavaCompile compileTask = target.getTasks().create(namingScheme.getTaskName("compile", "java"), JavaCompile.class); configureCompileTask(compileTask, javaSourceSet, binary); binary.builtBy(compileTask); } }); } }); ProjectSourceSet projectSourceSet = target.getExtensions().getByType(DefaultProjectSourceSet.class); projectSourceSet.all(new Action<FunctionalSourceSet>() { public void execute(final FunctionalSourceSet functionalSourceSet) { functionalSourceSet.registerFactory(JavaSourceSet.class, new NamedDomainObjectFactory<JavaSourceSet>() { public JavaSourceSet create(String name) { return instantiator.newInstance(DefaultJavaSourceSet.class, name, instantiator.newInstance(DefaultSourceDirectorySet.class, name, fileResolver), instantiator.newInstance(DefaultClasspath.class, fileResolver, target.getTasks()), functionalSourceSet); } }); } }); }
@Override public void execute(Task javaCompileTask) { val compilerArgs = JavacUtils.createJavacArgs(javaCompileTask.getProject()); val javaCompile = (JavaCompile)javaCompileTask; val options = javaCompile.getOptions(); options.setCompilerArgs(compilerArgs); }
@Override protected void registerWithJavac(Project project) { super.registerWithJavac(project); // "skipUses=javaslang" // remove warns to turn the checks into errors val options = asList(new Option("warns", "true"), new Option("lint", "-cast:unsafe")); registerAnnotationProcessorOptions(project, options); registerBootClasspath(project, bootClasspathFiles(project)); project.getTasks().withType(JavaCompile.class, it -> this.configureJavac(project, it)); }
@Override public void execute(Task javaCompileTask) { val javaCompile = (JavaCompile)javaCompileTask; val options = javaCompile.getOptions(); if (UtilsKt.isBuggyJavac()) { options.setFork(true); options.getForkOptions(). setJvmArgs(singletonList("-Xbootclasspath/p:" + compilerLibraryFile(project).getAbsolutePath())); } val compilerArgs = createJavacArgs(javaCompileTask.getProject()); options.setCompilerArgs(compilerArgs); }
private void configureCompileJJTreeTask(Project project) { CompileJjtreeTask compileJjtreeTask = (CompileJjtreeTask) project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE); if (compileJjtreeTask == null) { return; } if (!compileJjtreeTask.getSource().isEmpty()) { addJJTreeDependencyToJavaccCompileTask(project.getTasks().withType(JavaCompile.class), project.getTasks().withType(CompileJavaccTask.class), compileJjtreeTask); } }
@TaskAction public void run() { TaskCollection<JavaCompile> javaCompileTasks = this.getProject().getTasks().withType(JavaCompile.class); CompilerInputOutputConfiguration inputOutputDirectories = new JavaccCompilerInputOutputConfiguration(getInputDirectory(), getOutputDirectory(), getSource(), javaCompileTasks); JjdocProgramInvoker jjdocInvoker = new JjdocProgramInvoker(getProject(), getClasspath(), inputOutputDirectories.getTempOutputDirectory()); ProgramArguments arguments = new ProgramArguments(); arguments.addAll(getArguments()); SourceFileCompiler compiler = new JavaccSourceFileCompiler(jjdocInvoker, arguments, inputOutputDirectories, getLogger()); compiler.createTempOutputDirectory(); compiler.compileSourceFilesToTempOutputDirectory(); compiler.copyCompiledFilesFromTempOutputDirectoryToOutputDirectory(); compiler.cleanTempOutputDirectory(); }
public JavaccCompilerInputOutputConfiguration(File inputDirectory, File outputDirectory, FileTree source, TaskCollection<JavaCompile> javaCompileTasks) { this.inputDirectory = inputDirectory; this.outputDirectory = outputDirectory; this.source = source; this.javaCompileTasks = new HashSet<JavaCompile>(); if (!CollectionUtils.isEmpty(javaCompileTasks)) { this.javaCompileTasks.addAll(javaCompileTasks); } }
@Override public FileTree getJavaSourceTree() { FileTree javaSourceTree = null; for (JavaCompile task : javaCompileTasks) { if (javaSourceTree == null) { javaSourceTree = task.getSource(); } else { javaSourceTree = javaSourceTree.plus(task.getSource()); } } return excludeOutputDirectory(javaSourceTree); }
@Test public void compileJavaDependsOnCompileJavaccAfterExecutionWhenJavaPluginApplied() { applyJavaccPluginToProject(); applyJavaPluginToProject(); JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction(); action.execute(project); TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class); for (JavaCompile task : javaCompilationTasks) { Set<Object> dependencies = task.getDependsOn(); assertTrue(dependencies.contains(project.getTasks().findByName(CompileJavaccTask.TASK_NAME_VALUE))); } }
@Test public void compileJavaDoesNotDependOnCompileJavaccWhenJavaccPluginNotApplied() { applyJavaPluginToProject(); JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction(); action.execute(project); TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class); for (JavaCompile task : javaCompilationTasks) { Set<Object> dependencies = task.getDependsOn(); assertFalse(dependencies.contains(project.getTasks().findByName(CompileJavaccTask.TASK_NAME_VALUE))); } }
@Test public void compileJavaDoesNotDependOnCompileJJTreeWhenJavaccPluginNotApplied() { applyJavaPluginToProject(); JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction(); action.execute(project); TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class); for (JavaCompile task : javaCompilationTasks) { Set<Object> dependencies = task.getDependsOn(); assertFalse(dependencies.contains(project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE))); } }
@Test public void getJavaSourceTreeReturnsJavaCompileSourceWhenSingleJavaCompileTask() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, contains(javaFile.getCanonicalFile())); }
@Override public void apply(final Project project) { project.apply(Collections.singletonMap("plugin", ErrorProneBasePlugin.class)); final ErrorProneToolChain toolChain = ErrorProneToolChain.create(project); final Action<JavaCompile> action = task -> task.setToolChain(toolChain); final TaskCollection<JavaCompile> javaCompileTasks = project.getTasks().withType(JavaCompile.class); javaCompileTasks.all(action); javaCompileTasks.whenTaskAdded(action); }
private static GenerateAvroJavaTask configureJavaGenerationTask(final Project project, final SourceSet sourceSet, GenerateAvroProtocolTask protoTask) { String taskName = sourceSet.getTaskName("generate", "avroJava"); GenerateAvroJavaTask task = project.getTasks().create(taskName, GenerateAvroJavaTask.class); task.setDescription(String.format("Generates %s Avro Java source files from schema/protocol definition files.", sourceSet.getName())); task.setGroup(GROUP_SOURCE_GENERATION); task.source(getAvroSourceDir(project, sourceSet)); task.source(protoTask.getOutputDir()); task.source(protoTask.getOutputs()); task.include("**/*." + SCHEMA_EXTENSION, "**/*." + PROTOCOL_EXTENSION); task.getConventionMapping().map("outputDir", new Callable<File>() { @Override public File call() throws Exception { return getGeneratedOutputDir(project, sourceSet, JAVA_EXTENSION); } }); sourceSet.getJava().srcDir(task.getOutputDir()); final JavaCompile compileJavaTask = getCompileJavaTask(project, sourceSet); compileJavaTask.source(task.getOutputDir()); compileJavaTask.source(task.getOutputs()); final AvroExtension avroExtension = project.getExtensions().findByType(AvroExtension.class); ConventionMapping taskMapping = conventionMapping(task); taskMapping.map(OPTION_OUTPUT_CHARACTER_ENCODING, new Callable<String>() { @Override public String call() throws Exception { String compilationEncoding = compileJavaTask.getOptions().getEncoding(); String extensionEncoding = avroExtension.getOutputCharacterEncoding(); return compilationEncoding != null ? compilationEncoding : extensionEncoding; } }); return task; }
@Override public Class<JavaCompile> getType() { return JavaCompile.class; }
/** * AwbInstantRun is not supported for the moment * * @param javacTask */ @Override public void execute(JavaCompile javacTask) { // libVariantContext.setJavacTask(javacTask); javacTask.setSource(libVariantContext.getSourceOutputDir()); ConventionMappingHelper.map(javacTask, "classpath", new Callable<FileCollection>() { @Override public FileCollection call() { FileCollection classpath = scope.getJavaClasspath(); return classpath; } }); javacTask.setDestinationDir(libVariantContext.getJavaCDir()); //javacTask.setDependencyCacheDir(new File(scope.getGlobalScope().getIntermediatesDir(), // "/awb-dependency-cache/" + scope.getVariantConfiguration().getFullName() + "/" // + awbBundle.getName())); CompileOptions compileOptions = scope.getGlobalScope().getExtension().getCompileOptions(); AbstractCompilesUtil.configureLanguageLevel(javacTask, compileOptions, scope.getGlobalScope().getExtension().getCompileSdkVersion(), false); javacTask.getOptions().setEncoding(compileOptions.getEncoding()); javacTask.getOptions().setBootClasspath(Joiner.on(File.pathSeparator).join(scope.getGlobalScope().getAndroidBuilder().getBootClasspathAsStrings(false))); GlobalScope globalScope = scope.getGlobalScope(); Project project = globalScope.getProject(); boolean incremental; if (compileOptions.getIncremental() != null) { incremental = compileOptions.getIncremental(); } else { // if (globalScope.getExtension().getDataBinding().isEnabled() // || project.getPlugins().hasPlugin("com.neenbedankt.android-apt") // || project.getPlugins().hasPlugin("me.tatarka.retrolambda")) { // incremental = false; // } else { // For now, default to false, irrespective of Instant Run. incremental = false; // } } if (AndroidGradleOptions.isJavaCompileIncrementalPropertySet(project)) { scope.getGlobalScope().getAndroidBuilder().getErrorReporter().handleSyncError(null, SyncIssue.TYPE_GENERIC, String.format("The %s property has been replaced by a DSL property. Please add the " + "following to your build.gradle instead:\n" + "android {\n" + " compileOptions.incremental = false\n" + "}", AndroidGradleOptions.PROPERTY_INCREMENTAL_JAVA_COMPILE)); } if (incremental) { LOG.info("Using incremental javac compilation."); } else { LOG.info("Not using incremental javac compilation."); } javacTask.getOptions().setIncremental(incremental); }
@TaskAction void run() throws ExecutionException, InterruptedException { AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName()); if (null == atlasDependencyTree) { return; } BaseExtension androidExtension = appVariantOutputContext.getVariantContext().getAppExtension(); boolean isDatabindEnabled = null != androidExtension.getDataBinding() && androidExtension.getDataBinding() .isEnabled(); ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(),0); ExecutorServicesHelper executorServicesHelper2 = new ExecutorServicesHelper(taskName+"databinding", getLogger(), 1); List<Runnable> runnables = new ArrayList<>(); List<Runnable> runnables2 = new ArrayList<>(); for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) { Runnable runnable = new Runnable() { @Override public void run() { try { AwbJavaCompileConfigAction awbJavaCompileConfigAction = new AwbJavaCompileConfigAction( awbBundle, appVariantOutputContext); JavaCompile awbJavaCompile = TaskCreater.create(getProject(), awbJavaCompileConfigAction.getName(), awbJavaCompileConfigAction.getType()); awbJavaCompileConfigAction.execute(awbJavaCompile); awbJavaCompile.execute(); AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get( awbBundle.getName()); awbTransform.setInputDir(awbJavaCompile.getDestinationDir()); } catch (Throwable e) { e.printStackTrace(); throw new GradleException("javac " + awbBundle.getName() + " failed"); } } }; if (appVariantOutputContext.getVariantContext().isDataBindEnabled(awbBundle)){ runnables2.add(runnable); }else { runnables.add(runnable); } } executorServicesHelper.execute(runnables); executorServicesHelper2.execute(runnables2); }