Attaching Gradle sources in IntelliJ IDEA

試著忘記壹切 提交于 2020-12-27 08:53:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!