简体   繁体   English

如何针对本地依赖项运行Gradle JAR?

[英]How to run Gradle JAR against local dependencies?

When I run gradle clean jar it pulls down all my executable JAR's dependencies under ~/.gradle and then creates my JAR. 当我运行gradle clean jar它将~/.gradle下的所有可执行JAR的依赖项~/.gradle ,然后创建我的JAR。

I am then having to jump through serious hoops to run the JAR locally: 然后,我不得不跳过重重障碍才能在本地运行JAR:

  1. First I create a lib directory in the same folder as the newly-created JAR 首先,我在与新创建的JAR相同的文件夹中创建一个lib目录
  2. Then I have to cherry pick all of my project's transitive dependencies (there are lots) out from ~/.gradle and copy them to lib 然后,我必须从~/.gradle挑选出我项目的所有传递依赖项(有很多)并将它们复制到lib
  3. Then I run from the command-line java -jar myapp.jar -cp "lib/*" 然后,我从命令行java -jar myapp.jar -cp "lib/*"

Every time my dependencies change (new code is added, etc.) I have to go through this process, and it makes me wonder if there is a more elegant way to run your Gradle-built apps locally. 每当我的依赖项发生变化(添加新代码等)时,我都必须经历此过程,这使我想知道是否存在更优雅的方式在本地运行Gradle构建的应用程序。

I ended up going with the application plugin. 我最终选择了application插件。 It turns out that Gradle considers compile dependencies a subset of runtime so I didn't need to change any dependency scopes. 事实证明,Gradle将compile依赖项视为runtime的子集,因此我不需要更改任何依赖项范围。 I can now just issue gradle run and it runs my app beautifully. 我现在可以发出gradle run ,它可以很好地运行我的应用程序。

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

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