Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Use annotationProcessorGeneratedSourcesDirectory when it exists (Grad…
Browse files Browse the repository at this point in the history
…le 4.3+)
  • Loading branch information
tbroyer committed Nov 1, 2017
1 parent 6a02511 commit e1f4a53
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 33 deletions.
19 changes: 16 additions & 3 deletions src/main/java/net/ltgt/gradle/apt/AptPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
public class AptPlugin implements Plugin<Project> {
private static boolean HAS_ANNOTATION_PROCESSOR_PATH =
GradleVersion.current().compareTo(GradleVersion.version("3.4")) >= 0;
private static boolean HAS_ANNOTATION_PROCESSOR_GENERATED_SOURCES_DIRECTORY =
GradleVersion.current().compareTo(GradleVersion.version("4.3")) >= 0;

@Override
public void apply(final Project project) {
Expand Down Expand Up @@ -256,16 +258,26 @@ public void execute(Task task) {

boolean doUseAnnotationProcessorPath =
HAS_ANNOTATION_PROCESSOR_PATH && (task instanceof JavaCompile);
boolean doUseAnnotationProcessorGeneratedSourcesDirectory =
HAS_ANNOTATION_PROCESSOR_GENERATED_SOURCES_DIRECTORY
&& (task instanceof JavaCompile);

CompileOptions compileOptions =
getCompileOptions.getCompileOptions((T) task);
if (doUseAnnotationProcessorPath) {
compileOptions.setAnnotationProcessorPath(
aptConvention.aptOptions.getProcessorpath());
}
if (doUseAnnotationProcessorGeneratedSourcesDirectory) {
compileOptions.setAnnotationProcessorGeneratedSourcesDirectory(
aptConvention.getGeneratedSourcesDestinationDir());
}
compileOptions
.getCompilerArgs()
.addAll(aptConvention.buildCompilerArgs(!doUseAnnotationProcessorPath));
.addAll(
aptConvention.buildCompilerArgs(
!doUseAnnotationProcessorPath,
!doUseAnnotationProcessorGeneratedSourcesDirectory));
}
});
}
Expand Down Expand Up @@ -332,9 +344,10 @@ void makeDirectories() {
}
}

List<String> buildCompilerArgs(boolean shouldAddProcessorPath) {
List<String> buildCompilerArgs(
boolean shouldAddProcessorPath, boolean shouldAddProcessorGeneratedSourcesDirectory) {
List<String> result = new ArrayList<>();
if (generatedSourcesDestinationDir != null) {
if (shouldAddProcessorGeneratedSourcesDirectory && generatedSourcesDestinationDir != null) {
result.add("-s");
result.add(getGeneratedSourcesDestinationDir().getPath());
}
Expand Down
Loading

0 comments on commit e1f4a53

Please sign in to comment.