问题
Once after I create a Gradle project in IntelliJ using the default gradle wrapper and create directories option I see the project structure gets created with build.gradle file.
IntelliJ tips me to "You can configure Gradle wrapper to use distribution with sources. It will provide IDE with Gradle API/DSL documentation" - but I am not able to attach the sources even after clicking "Ok, apply suggestion". The Gradle project is getting refreshed but the sources are not attached.
We are using a Nexus repository.
回答1:
To improve on @anon58192932 answer you can use only gradleVersion and distributionType fields of Wrapper task and don't need to manually create distributionUrl which is more error prone since you could change gradle version in one place, but not in the other.
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
distributionType = Wrapper.DistributionType.ALL
}
@edit gradle 4.8+ will produce error for above. Use instead
wrapper {
gradleVersion = '4.2'
distributionType = Wrapper.DistributionType.ALL
}
回答2:
Sounds like some IntelliJ problem. To do this manually, change gradle-bin to gradle-all in $projectDir/gradle/wrapper/gradle-wrapper.properties.
回答3:
Peter's answer is not correct. The gradle-wrapper.properties and gradle-wrapper.jar files are generated by the 'wrapper' task which is shown in IntelliJ as a build task to perform.
When wrapper is performed it will build out the .jar and .properties file based on your settings therefore you should NOT be editing these files manually as they are GENERATED.
You can call the wrapper task manually very easily in your project folder: ./gradlew wrapper for *nix platforms. This will generate updated gradle-wrapper.properties and gradle-wrapper.jar files for your project.
If you want to specify to use all sources or not you can easily modify your main build.gradle file with the following:
allprojects {
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
distributionUrl = 'https://services.gradle.org/distributions/gradle-4.1-bin.zip'
}
}
Substitute gradle-4.1-bin.zip for gradle-4.1-all.zip to include gradle sources, documentation, and examples.
来源:https://stackoverflow.com/questions/26662271/attaching-gradle-sources-in-intellij-idea