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

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

Open
jpd236 opened this issue May 7, 2015 · 5 comments
Open

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

jpd236 opened this issue May 7, 2015 · 5 comments

Comments

@jpd236
Copy link
Contributor

jpd236 commented May 7, 2015

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 square/wire#177 (comment) 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
Copy link
Collaborator

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
Copy link

mingfai commented May 9, 2015

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
Copy link

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
Copy link

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

@tasomaniac
Copy link

tasomaniac commented Jan 18, 2017

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
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants