java - Gradle 在编译时包含 jar 但排除运行时
问题描述
我正在使用本地 jar,我javaee-api-6.0.jar
在编译时需要,但我想在运行时排除它。
dependencies {
// Add all the jar dependencies from the lib folder.
compile fileTree(dir: '../lib', include: ['/**/*.jar'])
//testImplementation fileTree(dir: '../lib', excludes: ['/**/javaee-api-*.jar'])
}
我试图在此期间排除它,testImplementation
但它没有帮助。运行时我得到以下错误。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'mycompany.persistence.HibernateBackwardsCompatibilifier#0' defined in class path resource
[hibernateBeans.xml]: Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[mycompany.persistence.HibernateBackwardsCompatibilifier]: Constructor threw exception; nested
exception is java.lang.ClassFormatError: Absent Code attribute in method that is not native or
abstract in class file javax/persistence/PersistenceException
如何在编译时包含jar 但排除运行时
解决方案
compileOnly
— 对于编译生产代码所必需但不应成为运行时类路径的一部分的依赖项
推荐阅读
- plot - 使用 sympy 时 y 轴不自动缩放
- python - 在熊猫中将一行乘以前一行(具有特定名称)
- c# - 仅当托管在 VM 的 IIS 服务器中但不在 localhost 中时,才会在 Blazor 应用程序中发生 Grpc 错误
- flutter - 将 BlocListener 与 Navigator PushNamed 一起使用会导致歧义
- python - AttributeError: 'bytes' 对象没有属性 'presence_of_element_located'
- javascript - 在 nuxt 中使用路由对象替换路径
- python - 将递归问题代码从 Python 转换为 Common Lisp
- d3.js - d3 事件处理程序的 d3.js 单元测试
- google-oauth - 用户在 Android 应用程序中看到未验证的应用程序屏幕
- node.js - 使用 yargs 将默认数值添加到可选参数