square / wire-gradle-plugin

A Gradle plugin for generating Java code for your protocol buffer definitions with Wire.
Apache License 2.0
153 stars 23 forks source link

Java plugin's generated code not discovered by IntelliJ #3

Open jpd236 opened 9 years ago

jpd236 commented 9 years ago

Unlike the Android plugin, the Java gradle plugin doesn't seem to provide a way to configure a directory as a generated source directory so that it gets picked up by the IDE as source, and have it generated when you click "Sync Now". See https://github.com/square/wire/pull/177#issuecomment-99777359 for the original report.

There are some hacky workarounds at http://stackoverflow.com/questions/16702126/how-to-specify-intellij-exclude-directories-using-gradle but none of them are particularly appealing. Notably, the question author there says they're using a protobuf plugin (not this one, ostensibly) that has this same problem.

JakeWharton commented 9 years ago

I think you can also just add the folder to the main source set. Will experiment with when I get some time.

sourceSets.main.srcDirs += 'build/generated/proto'
mingfai commented 9 years ago

for reference, I added a question to an old IDEA issue: https://youtrack.jetbrains.com/issue/IDEA-117540

probably won't get response and i'll create another issue later

alex-dorokhov commented 9 years ago

As another workaround you can also do this:

ext.generatedFilesDir = "${projectDir}/proto-gen-src"
tasks["generateWireProtos"].outputDir = file(generatedFilesDir)
tasks["clean"] << {
    file(generatedFilesDir).deleteDir()
}
sourceSets.main.java.srcDir generatedFilesDir

In general, I think it makes sense to provide an option to specify output directory for Wire task in easier way, and maybe make default output directory outside of "build" folder for Java projects.

tadfisher commented 9 years ago

Other plugins (net.ltgt.apt is one) test for the presence of the idea plugin and configure the IDE using that.

tasomaniac commented 7 years ago

So this plugin does not configure IntelliJ. But if you have any other plugin that does that, it should just work.

So apply both apt and idea to your java module.

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.ltgt.apt'
apply plugin: 'com.squareup.wire'

Then add this below in your build.gradle as well. Then it should work.

idea {
  module {
    sourceDirs += generateWireProtos.outputDir
  }
}