Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

[improvement] Configure annotation processor classpath explicitly in IDEA #97

Merged
merged 7 commits into from
Nov 12, 2018

Conversation

dansanduleac
Copy link
Contributor

@dansanduleac dansanduleac commented Nov 11, 2018

Before this PR

Currently, we configure a global "profile" for annotation processors in IDEA.
This profile instructs IDEA to pick up annotation processors from the classpath. At the same time, we manually add all dependencies from the processor configuration to the PROVIDED scope in IDEA.

This becomes problematic when an annotation processor brings in a different version of a library that already exists on your classpath. Now you get duplicates and behaviour is unexpected as it's not obvious which one will be used during compilation.

Additionally, this leaks all annotation processor dependencies (which are supposed to be implementation details as far as the rest of the program is concerned) onto your PROVIDED scope, so you could accidentally use a class that's not actually in your runtime configuration.

After this PR

The IDEA project is configured with one profile per gradle project, which is assigned to the corresponding IDEA module, and each project's complete set of annotation processors (configuration allProcessors) are enumerated in this profile.

Furthermore, we don't make IDEA's PROVIDED scope extend allProcessors anymore.
This means that processors added to gradle 4.6+'s annotationProcessor configuration (and equivalents for source sets other than main) don't leak onto your PROVIDED scope anymore.

However, we still add dependencies from the original processor configuration to PROVIDED in an effort to keep backwards compatibility.

Example diff for gradle-sls-packaging:

-   <profile default="true" name="Default" enabled="true">
+   <profile name=":gradle-sls-packaging" enabled="true">
        <sourceOutputDir name="generated_src"/>
        <sourceTestOutputDir name="generated_testSrc"/>
        <outputRelativeToContentRoot value="true"/>
-       <processorPath useClasspath="true"/>
+       <processorPath useClasspath="false">
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.immutables/value/2.7.1/7879e75c53074fd8cbbe014bfa5e8689f8c565ae/value-2.7.1.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.palantir.baseline/baseline-error-prone/0.37.4/5b2e810d8335af8a105bda5ebf546ae0684dbefa/baseline-error-prone-0.37.4.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_core/2.3.2/d5d121a23bcd48df2fe42dc3f1424cd05872993/error_prone_core-2.3.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_check_api/2.3.2/7415438c00adec8ba707689ec4168c8484d8403b/error_prone_check_api-2.3.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_annotation/2.3.2/7c554c59dd2ea8c4e9e36b3308f8bf92db83e70c/error_prone_annotation-2.3.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_type_annotations/2.3.2/e79e88b9051888c8ea806f49c86fa7e3e3728180/error_prone_type_annotations-2.3.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.github.stephenc.jcip/jcip-annotations/1.0-1/ef31541dd28ae2cefdd17c7ebf352d93e9058c63/jcip-annotations-1.0-1.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.pcollections/pcollections/2.1.2/15925fd6c32a29fe3f40a048d238c5ca58cb8362/pcollections-2.1.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.auto/auto-common/0.10/c8f153ebe04a17183480ab4016098055fb474364/auto-common-0.10.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/23.6.1-jre/c18ab06b4b7646be581211ad59be1b6e1ea4c278/guava-23.6.1-jre.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jFormatString/3.0.0/d3995f9be450813bc2ccee8f0774c1a3033a0f30/jFormatString-3.0.0.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.2/25ea2e8b0c338a877313bd4672d3fe056ea78f0d/jsr305-3.0.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.checkerframework/dataflow/2.5.3/edf284e0838290d661b22483ecf648065e7ec440/dataflow-2.5.3.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_annotations/2.3.2/d1a0c5032570e0f64be6b4d9c90cdeb103129029/error_prone_annotations-2.3.2.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/3.4.0/b32aba0cbe737a4ca953f71688725972e3ee927c/protobuf-java-3.4.0.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.googlecode.java-diff-utils/diffutils/1.3.0/7e060dd5b19431e6d198e91ff670644372f60fbd/diffutils-1.3.0.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.github.kevinstern/software-and-algorithms/1.0/5e77666b72c6c5dd583c36148d17fc47f944dfb5/software-and-algorithms-1.0.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.checkerframework/checker-compat-qual/2.0.0/fc89b03860d11d6213d0154a62bcd1c2f69b9efa/checker-compat-qual-2.0.0.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/com.google.j2objc/j2objc-annotations/1.1/ed28ded51a8b1c6b112568def5f4b455e6809019/j2objc-annotations-1.1.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.codehaus.mojo/animal-sniffer-annotations/1.14/775b7e22fb10026eed3f86e8dc556dfafe35f2d5/animal-sniffer-annotations-1.14.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.checkerframework/javacutil/2.5.3/c545ca6fc7a57e3bc65d46e8e9438376f0db35ea/javacutil-2.5.3.jar"/>
+           <entry name="/Users/dsanduleac/.gradle/caches/modules-2/files-2.1/org.checkerframework/checker-qual/2.5.3/4fe154d21bd734fe8c94ada37cdc41a9a6d61776/checker-qual-2.5.3.jar"/>
+       </processorPath>
+       <module name="gradle-sls-packaging"/>
    </profile>

@dansanduleac dansanduleac requested a review from a team as a code owner November 11, 2018 19:06
if (project.idea.module.scopes.PROVIDED != null) {
project.idea.module.scopes.PROVIDED.plus += [allProcessorConf]
if (idea.module.scopes.PROVIDED != null) {
idea.module.scopes.PROVIDED.plus += [ourProcessorConf]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance we could fully remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - the deps in ourProcessorConf (i.e. configurations.processor) will end up in compileOnly anyway at the moment so there's no logic break to just remove this entirely.

Note that whether we add ourProecssorConf or not, error prone would not be in there anyway, because it's a dependency of annotationProcessor, not processor.

@iamdanfox
Copy link
Contributor

If we can make sure that baseline-error-prone doesn't end up in the provided scope then I'd be super in favour of this!

They will end up there anyway, since we make `compileOnly` extend
`processor` anyway.  To remove them from the compilation classpath,
add them to `annotationProcessor` rather than `processor`.
@dansanduleac dansanduleac merged commit 88af1a8 into master Nov 12, 2018
@dansanduleac dansanduleac deleted the ds/enumerate-annotation-classpath branch November 12, 2018 15:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants