简体   繁体   中英

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:

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:

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?

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. Please check the documentation , section Dependency management . Try this one:

compileOnly Compile time only dependencies, not used at runtime

This should compile your project and the huge jar should not be included in the distribution. How you will refer it in runtime largely depends on your project type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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