How to download dependency sources for Gradle project in IDEA?
Intellij IdeaGradleIntellij Idea Problem Overview
It appears that the eclipse plugin uses the following mechanism to do this:
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
downloadSources=true
}
}
but I can't find a corresponding option for the idea plugin. What am I missing?
Here's the build.gradle file:
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
mavenCentral()
mavenRepo name: "Grails", url: "http://repo.grails.org/grails/repo/"
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.4'
compile 'org.slf4j:slf4j-log4j12:1.6.6', 'postgresql:postgresql:9.1-901.jdbc4', 'net.sourceforge.nekohtml:nekohtml:1.9.16'
['core', 'hibernate', 'plugin-datasource', 'plugin-domain-class'].each { plugin ->
compile "org.grails:grails-$plugin:2.1.0"
}
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
// Fat Jar Option (http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar)
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0'
}
Intellij Idea Solutions
Solution 1 - Intellij Idea
I've got problems with the following configuration:
idea {
module {
// if you hate browsing Javadoc
downloadJavadoc = false
// and love reading sources :)
downloadSources = true
}
}
repositories {
mavenLocal()
mavenCentral()
}
When removed mavenLocal()
sources were downloaded and attached.
Solution 2 - Intellij Idea
For Kotlin DSL:
plugins {
idea
}
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
Solution 3 - Intellij Idea
I noticed that when you already have a jar downloaded then its sources and not downloading after changing build.gradle.
Removing .m2 from my home directory and calling gradle helped.
Solution 4 - Intellij Idea
If you need to keep mavenLocal()
repository due to dependencies on snapshot jars (or some other reasons), you can get the source jar using maven.
mvn dependency:get -Dartifact=GROUP_ID:ARTIFACT_ID:VERSION:jar:sources
For example,
mvn dependency:get -Dartifact=org.springframework:spring-core:5.1.2.RELEASE:jar:sources