Last active
October 30, 2018 17:09
-
-
Save tbroyer/406b5c8b1d5c2b401d64c8e1ad84a3ce to your computer and use it in GitHub Desktop.
Goodbye `net.ltgt.apt-idea` 👋
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this file in ~/.gradle/init.d/ | |
// | |
// It will automatically configure Java projects (not Groovy) with for use in IntelliJ IDEA, | |
// by declaring options.annotationProcessorGeneratedSourcesDirectory as generated sources | |
// (assumes "Delegate IDE build/run actions to gradle" and "Create separate module per source set"; | |
// only works for 'main' and 'test' source sets). | |
// The options.annotationProcessorGeneratedSourcesDirectory still needs to be configured in builds | |
// (see https://github.com/gradle/gradle/issues/4956). This script is thus mainly a workaround for | |
// the IDEA issue https://youtrack.jetbrains.com/issue/IDEA-182577 | |
// | |
// In Gradle < 4.6, falls back to applying net.ltgt.apt-idea whenever net.ltgt.apt is applied | |
import org.gradle.util.GradleVersion; | |
if (Boolean.getBoolean("idea.active")) { | |
def HAS_ANNOTATION_PROCESSOR_PATH = GradleVersion.current() >= GradleVersion.version("4.6") | |
allprojects { project -> | |
project.apply plugin: 'idea' | |
if (HAS_ANNOTATION_PROCESSOR_PATH) { | |
project.plugins.withType(JavaPlugin) { | |
project.afterEvaluate { | |
project.idea.module { | |
def mainGeneratedSources = project.tasks["compileJava"].options.annotationProcessorGeneratedSourcesDirectory | |
if (mainGeneratedSources) { | |
sourceDirs += mainGeneratedSources | |
generatedSourceDirs += mainGeneratedSources | |
} | |
def testGeneratedSources = project.tasks["compileTestJava"].options.annotationProcessorGeneratedSourcesDirectory | |
if (testGeneratedSources) { | |
testSourceDirs += testGeneratedSources | |
generatedSourceDirs += testGeneratedSources | |
} | |
} | |
} | |
} | |
} else { | |
project.plugins.withId("net.ltgt.apt") { | |
try { | |
project.apply plugin: "net.ltgt.apt-idea" | |
project.plugins.withType(JavaPlugin) { | |
project.afterEvaluate { | |
project.idea.module.apt.addAptDependencies = false | |
} | |
} | |
} catch (UnknownPluginException) {} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To configure
options.annotationProcessorGeneratedSourcesDirectory
in your build, you can use thenet.ltgt.apt
plugin, or something like the following (assuming Gradle 4.9+ here):Groovy DSL
Kotlin DSL