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

Commit

Permalink
Remove annotation processor dependencies from IDEA scopes (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored and bulldozer-bot[bot] committed Jan 7, 2020
1 parent c584526 commit 040cc09
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-144.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: improvement
improvement:
description: Remove annotation processor dependencies from IDEA scopes, to avoid
potentially getting two different versions of the same jar in your PROVIDED or
TEST scopes in IDEA (one from `(test)annotationProcessor`, one from `(test)compileClasspath`).
links:
- https://github.com/palantir/gradle-processors/pull/144
14 changes: 14 additions & 0 deletions src/main/groovy/org/inferred/gradle/ProcessorsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import org.gradle.plugins.ide.eclipse.EclipsePlugin
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaModule
import org.gradle.plugins.ide.idea.model.internal.GeneratedIdeaScope
import org.gradle.plugins.ide.idea.model.internal.IdeaDependenciesProvider
import org.gradle.util.GradleVersion

class ProcessorsPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -154,6 +156,18 @@ class ProcessorsPlugin implements Plugin<Project> {
addGeneratedSourceFolder(project, { getIdeaSourceOutputDir(project) }, false)
addGeneratedSourceFolder(project, { getIdeaSourceTestOutputDir(project) }, true)

// We need to remove the configurations from the plus configurations.
// If we instead added the configurations from the minus configurations, then that would remove dependencies that
// are shared with other configurations in the plus configurations.
idea.module.scopes
.get(GeneratedIdeaScope.PROVIDED.name())
.get(IdeaDependenciesProvider.SCOPE_PLUS)
.remove(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME)
idea.module.scopes
.get(GeneratedIdeaScope.TEST.name())
.get(IdeaDependenciesProvider.SCOPE_PLUS)
.remove(JavaPlugin.TEST_ANNOTATION_PROCESSOR_CONFIGURATION_NAME)

// Root project configuration
def rootModel = project.rootProject.extensions.findByType(IdeaModel)
if (rootModel != null && rootModel.project != null) {
Expand Down
38 changes: 22 additions & 16 deletions src/test/groovy/org/inferred/gradle/ProcessorsPluginTest.groovy
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.inferred.gradle

import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Ignore
import org.junit.Test

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertTrue

class ProcessorsPluginTest {

@Test
public void addsProcessorDependenciesToJavaClasspath() {
void addsProcessorDependenciesToJavaClasspath() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'org.inferred.processors'
project.pluginManager.apply 'java'
Expand All @@ -23,18 +22,18 @@ class ProcessorsPluginTest {
}

@Test
public void addsSourceDirectoryConfiguration() {
void addsSourceDirectoryConfiguration() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'org.inferred.processors'
project.pluginManager.apply 'idea'
project.pluginManager.apply 'java'
project.pluginManager.apply 'idea'

assertEquals 'generated_src', project.idea.processors.outputDir
assertEquals 'generated_testSrc', project.idea.processors.testOutputDir
}

@Test
public void addsEclipseConfigurationTasks_processorsFirst() {
void addsEclipseConfigurationTasks_processorsFirst() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'org.inferred.processors'
project.pluginManager.apply 'java'
Expand All @@ -45,7 +44,7 @@ class ProcessorsPluginTest {
}

@Test
public void addsEclipseConfigurationTasks_processorsLast() {
void addsEclipseConfigurationTasks_processorsLast() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'java'
project.pluginManager.apply 'eclipse'
Expand All @@ -56,7 +55,18 @@ class ProcessorsPluginTest {
}

@Test
public void configuresIdeaGeneratedSourcesDirectories() {
void addsEclipseConfigurationTasks_eclipseFirst() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'org.inferred.processors'
project.pluginManager.apply 'eclipse'
project.pluginManager.apply 'java'

assertNotNull project.tasks.eclipseAptPrefs
assertNotNull project.tasks.eclipseFactoryPath
}

@Test
void configuresIdeaGeneratedSourcesDirectories() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'org.inferred.processors'
project.pluginManager.apply 'java'
Expand All @@ -69,17 +79,13 @@ class ProcessorsPluginTest {
}

@Test
public void addsEclipseConfigurationTasks_eclipseFirst() {
void configuredIdeaScopes() {
Project project = ProjectBuilder.builder().build()
project.pluginManager.apply 'org.inferred.processors'
project.pluginManager.apply 'eclipse'
project.pluginManager.apply 'java'
project.pluginManager.apply 'idea'

assertNotNull project.tasks.eclipseAptPrefs
assertNotNull project.tasks.eclipseFactoryPath
}

private static JavaPluginConvention getJavaConvention(Project project) {
project.convention.plugins['java'] as JavaPluginConvention
assertFalse project.idea.module.scopes.PROVIDED.plus.contains(project.configurations['annotationProcessor'])
assertFalse project.idea.module.scopes.TEST.plus.contains(project.configurations['testAnnotationProcessor'])
}
}

0 comments on commit 040cc09

Please sign in to comment.