简体   繁体   English

使用Gradle下载外部依赖而不编译?

[英]Use Gradle to download external dependencies without compiling?

Can I use Gradle to download Java external dependencies without compiling my source code?我可以使用 Gradle 下载 Java 外部依赖项而不编译我的源代码吗?

The external dependencies have made big changes to package structure since I created my code.自从我创建代码以来,外部依赖项对包结构进行了重大更改。 I would like to use Gradle to download the new versions and then fix my import statements using the tools in my IDE.我想使用 Gradle 下载新版本,然后使用我的 IDE 中的工具修复我的导入语句。

Gradle build seems to be failing without downloading the dependencies because it can't compile my source. Gradle 构建似乎在没有下载依赖项的情况下失败,因为它无法编译我的源代码。

Thanks.谢谢。

You can't download your dependencies with some custom task, which aims just for that.您无法使用一些自定义任务下载您的依赖项,而这些任务正是为此而设计的。 Dependencies are downloaded on demand, that means, that if you have changed dependencies versions in your gradle build script and then call the task, which have to compile your sources, all the dependencies will be downloaded.依赖项是按需下载的,这意味着,如果您在 gradle 构建脚本中更改了依赖项版本,然后调用必须编译源的任务,则将下载所有依赖项。 Sure, if the imports get wrong, your build will fail and you'll need to update your imports.当然,如果导入出错,您的构建将失败,您需要更新导入。

So, in other words, if you've changed dependencies versions and then called some task, that compile your sources, your dependencies will be downloaded automatically before the compilation start.因此,换句话说,如果您更改了依赖项版本,然后调用了一些编译源的任务,那么您的依赖项将在编译开始之前自动下载。

Here is a gradle task to download manually all dependency sources https://gist.github.com/ngtignacio/d0720b7a565729037d0fef1936655793这是一个手动下载所有依赖源的 gradle 任务https://gist.github.com/ngtignacio/d0720b7a565729037d0fef1936655793

I adapted the script at https://stackoverflow.com/a/58748741/2439283我在https://stackoverflow.com/a/58748741/2439283修改了脚本

It should download all available sources even if the project does not compile.即使项目没有编译,它也应该下载所有可用的源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM