diff --git a/README.md b/README.md index a3d77e3..3e5232e 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ If you're interested in better IDE support, please vote for those issues to even * in IntelliJ IDEA: [for annotation processing in the IDE](https://youtrack.jetbrains.com/issue/IDEA-187868), and/or simply [`options.annotationProcessorGeneratedSourcesDirectory` (e.g. if delegating build/run actions to Gradle)](https://youtrack.jetbrains.com/issue/IDEA-182577) -**Note: the documentation below only applies to version 0.20. For previous versions, please see [the previous version of this README](https://github.com/tbroyer/gradle-apt-plugin/blob/648bf2810097799796fdeb327255cdc99733aabd/README.md).** +**Note: the documentation below only applies to version 0.21. +For version 0.20, see [the previous version of this README](https://github.com/tbroyer/gradle-apt-plugin/blob/v0.20/README.md). +For previous versions, please see [this even earlier version](https://github.com/tbroyer/gradle-apt-plugin/blob/648bf2810097799796fdeb327255cdc99733aabd/README.md).** ## Do without the plugin @@ -319,8 +321,9 @@ eclipse { apt { // whether annotation processing is enabled in Eclipse aptEnabled = compileJava.aptOptions.annotationProcessing - // where Eclipse will output the generated sources; value is interpreted as per project.file() + // where Eclipse will output the generated sources; values are interpreted as per project.file() genSrcDir = file('.apt_generated') + genTestSrcDir = file('.apt_generated_tests') // whether annotation processing is enabled in the editor reconcileEnabled = true // a map of annotation processor options; a null value will pass the argument as -Akey rather than -Akey=value @@ -365,8 +368,9 @@ eclipse { apt { // whether annotation processing is enabled in Eclipse isAptEnabled = tasks.getByName("compileJava").aptOptions.annotationProcessing - // where Eclipse will output the generated sources; value is interpreted as per project.file() + // where Eclipse will output the generated sources; values are interpreted as per project.file() genSrcDir = file(".apt_generated") + genTestSrcDir = file(".apt_generated_tests") // whether annotation processing is enabled in the editor isReconcileEnabled = true // a map of annotation processor options; a null value will pass the argument as -Akey rather than -Akey=value diff --git a/src/main/java/net/ltgt/gradle/apt/EclipseJdtApt.java b/src/main/java/net/ltgt/gradle/apt/EclipseJdtApt.java index 6184303..9c5200a 100644 --- a/src/main/java/net/ltgt/gradle/apt/EclipseJdtApt.java +++ b/src/main/java/net/ltgt/gradle/apt/EclipseJdtApt.java @@ -42,6 +42,8 @@ public EclipseJdtApt(Project project, PropertiesFileContentMerger file) { reconcileEnabled.set(true); this.genSrcDir = project.getObjects().property(File.class); genSrcDir.set(project.file(".apt_generated")); + this.genTestSrcDir = project.getObjects().property(File.class); + genTestSrcDir.set(project.file(".apt_generated_tests")); this.processorOptions = (Property>) (Property) project.getObjects().property(Map.class); processorOptions.set(new LinkedHashMap<>()); @@ -90,6 +92,21 @@ public void setGenSrcDir(Object genSrcDir) { this.genSrcDir.set(project.provider(() -> project.file(genSrcDir))); } + private final Property genTestSrcDir; + + public File getGenTestSrcDir() { + return project.file(genTestSrcDir); + } + + public void setGenTestSrcDir(File genTestSrcDir) { + this.genTestSrcDir.set(Objects.requireNonNull(genTestSrcDir)); + } + + public void setGenTestSrcDir(Object genTestSrcDir) { + Objects.requireNonNull(genTestSrcDir); + this.genTestSrcDir.set(project.provider(() -> project.file(genTestSrcDir))); + } + private final Property> processorOptions; @Nullable diff --git a/src/main/java/net/ltgt/gradle/apt/GenerateEclipseJdtApt.java b/src/main/java/net/ltgt/gradle/apt/GenerateEclipseJdtApt.java index 8300506..86520dc 100644 --- a/src/main/java/net/ltgt/gradle/apt/GenerateEclipseJdtApt.java +++ b/src/main/java/net/ltgt/gradle/apt/GenerateEclipseJdtApt.java @@ -30,6 +30,7 @@ protected void configure(JdtApt jdtApt) { jdtAptModel.getFile().getBeforeMerged().execute(jdtApt); jdtApt.setAptEnabled(jdtAptModel.isAptEnabled()); jdtApt.setGenSrcDir(getProject().relativePath(jdtAptModel.getGenSrcDir())); + jdtApt.setGenTestSrcDir(getProject().relativePath(jdtAptModel.getGenTestSrcDir())); jdtApt.setReconcileEnabled(jdtAptModel.isReconcileEnabled()); jdtApt.getProcessorOptions().clear(); if (jdtAptModel.getProcessorOptions() != null) { diff --git a/src/main/java/net/ltgt/gradle/apt/JdtApt.java b/src/main/java/net/ltgt/gradle/apt/JdtApt.java index a7841cb..1827678 100644 --- a/src/main/java/net/ltgt/gradle/apt/JdtApt.java +++ b/src/main/java/net/ltgt/gradle/apt/JdtApt.java @@ -25,6 +25,7 @@ public class JdtApt extends PropertiesPersistableConfigurationObject { private static final String GEN_SRC_DIR_KEY = "org.eclipse.jdt.apt.genSrcDir"; + private static final String GEN_TEST_SRC_DIR_KEY = "org.eclipse.jdt.apt.genTestSrcDir"; private static final String RECONCILE_ENABLED_KEY = "org.eclipse.jdt.apt.reconcileEnabled"; private static final String PROCESSOR_OPTIONS_KEY_PREFIX = "org.eclipse.jdt.apt.processorOptions/"; @@ -32,6 +33,7 @@ public class JdtApt extends PropertiesPersistableConfigurationObject { private boolean aptEnabled; @Nullable private String genSrcDir; + @Nullable private String genTestSrcDir; private boolean reconcileEnabled; private Map processorOptions = new LinkedHashMap<>(); @@ -48,6 +50,7 @@ protected String getDefaultResourceName() { protected void load(Properties properties) { // Ignore aptEnabled when loading, see comment about storing it genSrcDir = properties.getProperty(GEN_SRC_DIR_KEY); + genTestSrcDir = properties.getProperty(GEN_TEST_SRC_DIR_KEY); reconcileEnabled = Boolean.parseBoolean(RECONCILE_ENABLED_KEY); for (String name : properties.stringPropertyNames()) { if (name.startsWith(PROCESSOR_OPTIONS_KEY_PREFIX)) { @@ -68,6 +71,7 @@ protected void store(Properties properties) { properties.setProperty("org.eclipse.jdt.apt.aptEnabled", Boolean.toString(isAptEnabled())); properties.setProperty(GEN_SRC_DIR_KEY, getGenSrcDir()); + properties.setProperty(GEN_TEST_SRC_DIR_KEY, getGenTestSrcDir()); properties.setProperty(RECONCILE_ENABLED_KEY, Boolean.toString(isReconcileEnabled())); for (String name : properties.stringPropertyNames()) { if (name.startsWith(PROCESSOR_OPTIONS_KEY_PREFIX) @@ -100,6 +104,15 @@ public void setGenSrcDir(@Nullable String genSrcDir) { this.genSrcDir = genSrcDir; } + @Nullable + public String getGenTestSrcDir() { + return genTestSrcDir; + } + + public void setGenTestSrcDir(@Nullable String genTestSrcDir) { + this.genTestSrcDir = genTestSrcDir; + } + public boolean isReconcileEnabled() { return reconcileEnabled; } diff --git a/src/main/resources/net/ltgt/gradle/apt/defaultJdtAptPrefs.properties b/src/main/resources/net/ltgt/gradle/apt/defaultJdtAptPrefs.properties index 7d52ece..fa6bcfb 100644 --- a/src/main/resources/net/ltgt/gradle/apt/defaultJdtAptPrefs.properties +++ b/src/main/resources/net/ltgt/gradle/apt/defaultJdtAptPrefs.properties @@ -1,4 +1,5 @@ eclipse.preferences.version=1 org.eclipse.jdt.apt.aptEnabled=true org.eclipse.jdt.apt.genSrcDir=.apt_generated +org.eclipse.jdt.apt.genTestSrcDir=.apt_generated_tests org.eclipse.jdt.apt.reconcileEnabled=true diff --git a/src/test/groovy/net/ltgt/gradle/apt/EclipseIntegrationSpec.groovy b/src/test/groovy/net/ltgt/gradle/apt/EclipseIntegrationSpec.groovy index 004b4df..bd83dbe 100644 --- a/src/test/groovy/net/ltgt/gradle/apt/EclipseIntegrationSpec.groovy +++ b/src/test/groovy/net/ltgt/gradle/apt/EclipseIntegrationSpec.groovy @@ -134,6 +134,7 @@ class EclipseIntegrationSpec extends Specification { def aptSettings = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs') aptSettings.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'true' aptSettings.getProperty('org.eclipse.jdt.apt.genSrcDir') == '.apt_generated' + aptSettings.getProperty('org.eclipse.jdt.apt.genTestSrcDir') == '.apt_generated_tests' aptSettings.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'true' // Test idempotency of eclipseFactorypath @@ -254,6 +255,7 @@ class EclipseIntegrationSpec extends Specification { apt { aptEnabled = false genSrcDir = file('whatever') + genTestSrcDir = file('tests_whatever') reconcileEnabled = false file.whenMerged { processorOptions.baz = 'qux' @@ -294,6 +296,7 @@ class EclipseIntegrationSpec extends Specification { def aptSettings = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs') aptSettings.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'false' aptSettings.getProperty('org.eclipse.jdt.apt.genSrcDir') == 'whatever' + aptSettings.getProperty('org.eclipse.jdt.apt.genTestSrcDir') == 'tests_whatever' aptSettings.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'false' aptSettings.getProperty('org.eclipse.jdt.apt.processorOptions/foo') == 'bar' aptSettings.getProperty('org.eclipse.jdt.apt.processorOptions/baz') == 'qux' @@ -315,6 +318,7 @@ class EclipseIntegrationSpec extends Specification { def aptSettings2 = loadProperties('.settings/org.eclipse.jdt.apt.core.prefs') aptSettings2.getProperty('org.eclipse.jdt.apt.aptEnabled') == 'false' aptSettings2.getProperty('org.eclipse.jdt.apt.genSrcDir') == 'whatever' + aptSettings2.getProperty('org.eclipse.jdt.apt.genTestSrcDir') == 'tests_whatever' aptSettings2.getProperty('org.eclipse.jdt.apt.reconcileEnabled') == 'false' aptSettings2.getProperty('org.eclipse.jdt.apt.processorOptions/quux') == 'bar' !aptSettings2.containsKey('org.eclipse.jdt.apt.processorOptions/foo') diff --git a/src/test/groovy/net/ltgt/gradle/apt/KotlinDslIntegrationSpec.groovy b/src/test/groovy/net/ltgt/gradle/apt/KotlinDslIntegrationSpec.groovy index b98aa21..ab81cc2 100644 --- a/src/test/groovy/net/ltgt/gradle/apt/KotlinDslIntegrationSpec.groovy +++ b/src/test/groovy/net/ltgt/gradle/apt/KotlinDslIntegrationSpec.groovy @@ -129,6 +129,7 @@ class KotlinDslIntegrationSpec extends Specification { apt { isAptEnabled = true genSrcDir = file(".apt_generated") + genTestSrcDir = file(".apt_generated_tests") isReconcileEnabled = true processorOptions = mapOf("foo" to "bar") }