Build.gradle 中的运行时范围编译失败。

huangapple go评论65阅读模式
英文:

Compile failed with runtime scope in Build.gradle?

问题

我有一个基于Gradle构建工具的Java Web项目,
我有一些在运行时需要的jar依赖项,
当我在build.gradle中将它们声明为runtime时,
在Eclipse代码中没有错误,所有代码看起来都很好,没有错误,
但是当我在项目中运行gradlew clean build时,我得到了这个错误:

> 任务:compileJava 失败
>
> 失败:构建过程因异常而失败。
>
> * 失败原因:执行任务':compileJava'失败。
> > 编译失败;有关详细信息,请参阅编译器错误输出。

另外,当我将范围更改为compileOnly时,编译工作正常,但我需要它是runtime范围!
有没有办法让范围保持为runtime并且项目能够成功编译?

谢谢

英文:

I have a java web project which is based on gradle as build tool,
I have some jars dependencies which I need them at runtime and when I declare them as runtime in the build.grale In eclipse code there are no errors and all code looks nice without errors but when I run gradlew clean build in the project I have this:

> Task :compileJava FAILED
>
> FAILURE: Build failed with an exception.
>
> * What went wrong: Execution failed for task ':compileJava'.
> > Compilation failed; see the compiler error output for details.

ALSO when I change the scope to compileOnly the compilation is working fine, but I need it runtime scope!

Is there a solution on how to make the scope runtime and the project compile fine ?

Thanks

答案1

得分: 1

你应该使用 implementation,以便在编译时和运行时都使依赖可用。

英文:

You should use implementation in order to make the dependency available both at compile time and at run time.

huangapple
  • 本文由 发表于 2020年9月2日 16:32:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63701671.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定