简体   繁体   English

在运行时而不是在编译时将jar文件添加到Gradle类路径中?

[英]Add a jar file to Gradle classpath at runtime and not at compile time?

Typically when adding a JAR to include with Gradle compilation I do the following: 通常,在添加要包含在Gradle编译中的JAR时,请执行以下操作:

compile files('lib/sentiment-models.jar')

However, since the JAR I'm trying to include is quite big (200MB) my goal is to instead include it at runtime, similar to how you would add files to the classpath using the java command: 但是,由于我要包含的JAR非常大(200MB),因此我的目标是在运行时包含它,类似于使用java命令将文件添加到类路径中的方式:

java -cp lib/sentiment-models.jar:. -jar /app/server.jar

So is there a way to use gradle run while including files at runtime, preferably in the build.gradle config file? 那么有没有一种方法可以gradle run时包含gradle run同时添加文件,最好是在build.gradle配置文件中?

Thanks! 谢谢!

Update 更新资料

I also tried 我也试过

runtime files('lib/sentiment-models.jar')

but it doesn't seem to work. 但它似乎不起作用。

I believe that you are using the Java plugin. 我相信您正在使用Java插件。 Please check the documentation , section Dependency management . 请检查文档“ Dependency management部分。 Try this one: 试试这个:

compileOnly Compile time only dependencies, not used at runtime compileOnly仅编译时依赖项,在运行时不使用

This should compile your project and the huge jar should not be included in the distribution. 这应该编译您的项目,并且不应该在发行版中包含巨大的jar。 How you will refer it in runtime largely depends on your project type. 在运行时如何引用它很大程度上取决于您的项目类型。

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

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