I've set up a Java project with IntelliJ and Gradle. I have a build.gradle file in my root project and I can compile and run my app.
However... I'm using a Java library which comes with a sources and javadoc zip file. If I'm in my source code and want to go to the declaration of a class or method from this library, IntelliJ brings up the .class
file instead of the source .java
file provided in the zip.
How can I tell gradle to use the sources and javadoc zips provided with the external library?
From the main menu, select File | Project Structure | Project Settings | Modules. Select the module for which you want to add a library and click Dependencies. button and select Library. In the dialog that opens, select a project or a global library that you want to add to the module.
View Javadocs in the editorHover the mouse over the necessary symbol in the editor. Place the caret at the symbol and press Ctrl+Q (View | Quick Documentation). Press Ctrl+Q again to open this documentation in the Documentation tool window.
I'm not sure if your library is stored in a maven repository or not. I assume it is.
I know of two ways of importing a gradle project into IntelliJ. The first being the "Import Project..." wizard from IntelliJ which works nicely. But it does not import the javadoc jars if they exist. At least I never managed it.
The second method uses the idea plugin in gradle 2.1. The plugin generates the project for you. This way I got the javadoc inside. A fully working example for a build.gradle:
apply plugin: 'java' apply plugin: 'idea' sourceCompatibility = '1.7' targetCompatibility = '1.7' repositories { mavenCentral() } dependencies { compile group: 'org.apache.commons', name: 'commons-compress', version: '1.8.1' compile group: 'com.google.guava', name: 'guava', version: '18.0' testCompile group: 'junit', name: 'junit', version: '4.11' testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.5' } idea{ project { languageLevel = '1.7' } module { downloadJavadoc = true // defaults to false downloadSources = true } }
The you can call gradle cleanIdea idea
which creates your project for IntelliJ.
If your library is not stored in a maven repository you can simply put up a nexus where you upload it. This would allow you to use the method described above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With