diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index ed576d90..2a31bdfd 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -527,17 +527,17 @@ class ProtobufPlugin implements Plugin { getSourceSets().each { sourceSet -> SourceDirectorySet protoSrcDirSet = sourceSet.proto protoSrcDirSet.srcDirs.each { File protoDir -> - Utils.addToIdeSources(project, Utils.isTest(sourceSet.name), protoDir) + Utils.addToIdeSources(project, Utils.isTest(sourceSet.name), protoDir, false) } } // Make the extracted proto dirs known to IDEs project.tasks.withType(ProtobufExtract).each { ProtobufExtract extractProtoTask -> - Utils.addToIdeSources(project, extractProtoTask.isTest, extractProtoTask.destDir) + Utils.addToIdeSources(project, extractProtoTask.isTest, extractProtoTask.destDir, true) } // Make the generated code dirs known to IDEs project.tasks.withType(GenerateProtoTask).each { GenerateProtoTask generateProtoTask -> generateProtoTask.getOutputSourceDirectorySet().srcDirs.each { File outputDir -> - Utils.addToIdeSources(project, generateProtoTask.isTest, outputDir) + Utils.addToIdeSources(project, generateProtoTask.isTest, outputDir, true) } } } diff --git a/src/main/groovy/com/google/protobuf/gradle/Utils.groovy b/src/main/groovy/com/google/protobuf/gradle/Utils.groovy index 1005efc0..4dd26bbe 100644 --- a/src/main/groovy/com/google/protobuf/gradle/Utils.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/Utils.groovy @@ -125,16 +125,17 @@ class Utils { * Adds the file to the IDE plugin's set of sources / resources. If the directory does * not exist, it will be created before the IDE task is run. */ - static void addToIdeSources(Project project, boolean isTest, File f) { + static void addToIdeSources(Project project, boolean isTest, File f, boolean isGenerated) { IdeaModel model = project.getExtensions().findByType(IdeaModel) if (model != null) { - // TODO(zpencer): switch to model.module.generatedSourceDirs when that API becomes stable - // For now, just hint to the IDE that it's a source dir or a test source dir. if (isTest) { model.module.testSourceDirs += f } else { model.module.sourceDirs += f } + if (isGenerated) { + model.module.generatedSourceDirs += f + } project.tasks.withType(GenerateIdeaModule).each { it.doFirst { // This is required because the intellij plugin does not allow adding source directories diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy index 71f6b1ed..6836a1db 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy @@ -363,12 +363,16 @@ class ProtobufJavaPluginTest extends Specification { Set sourceDir = [] as Set Set testSourceDir = [] as Set + Set generatedDirs = [] as Set rootMgr.content.sourceFolder[0].each { if (Boolean.parseBoolean(it.@isTestSource)) { testSourceDir.add(it.@url) } else { sourceDir.add(it.@url) } + if (Boolean.parseBoolean(it.@generated)) { + generatedDirs.add(it.@url) + } } Set expectedSourceDir = ImmutableSet.builder() @@ -390,8 +394,21 @@ class ProtobufJavaPluginTest extends Specification { .add('file://$MODULE_DIR$/build/extracted-include-protos/test') .add('file://$MODULE_DIR$/build/generated/source/proto/test/java') .build() + Set expectedGeneratedDirs = [ + 'file://$MODULE_DIR$/build/extracted-include-protos/grpc', + 'file://$MODULE_DIR$/build/extracted-protos/main', + 'file://$MODULE_DIR$/build/extracted-include-protos/main', + 'file://$MODULE_DIR$/build/extracted-protos/grpc', + 'file://$MODULE_DIR$/build/generated/source/proto/grpc/java', + 'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output', + 'file://$MODULE_DIR$/build/generated/source/proto/main/java', + 'file://$MODULE_DIR$/build/extracted-protos/test', + 'file://$MODULE_DIR$/build/extracted-include-protos/test', + 'file://$MODULE_DIR$/build/generated/source/proto/test/java', + ] assert Objects.equals(expectedSourceDir, sourceDir) assert Objects.equals(expectedTestSourceDir, testSourceDir) + Objects.equals(expectedGeneratedDirs, generatedDirs) where: gradleVersion << GRADLE_VERSIONS