英文:
Gradle include jar during compile time but exclude runtime
问题
I'm using local jars and I need javaee-api-6.0.jar
during compile time but I want to exclude it during runtime.
dependencies {
// Add all the jar dependencies from the lib folder.
compile fileTree(dir: '../lib', include: ['/**/*.jar'])
// testImplementation fileTree(dir: '../lib', excludes: ['/**/javaee-api-*.jar'])
}
I tried to exclude it during testImplementation
but it doesn't help. runtime I got below error.
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
How can I include jar during compile time but exclude it at runtime?
英文:
I'm using local jars and I need javaee-api-6.0.jar
during compile time but I want to exclude it during runtime.
dependencies {
// Add all the jar dependencies from the lib folder.
compile fileTree(dir: '../lib', include: ['/**/*.jar'])
//testImplementation fileTree(dir: '../lib', excludes: ['/**/javaee-api-*.jar'])
}
I tried to exclude it during testImplementation
but it doesn't help. runtime I got below error.
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
How can I include jar during compile time but exclude runtime
答案1
得分: 1
compileOnly
— 用于编译生产代码所需但不应成为运行时类路径的依赖项
英文:
compileOnly
— for dependencies that are necessary to compile your production code but shouldn’t be part of the runtime classpath
答案2
得分: 0
我使用了以下技巧。
dependencies {
compile fileTree(dir: '../lib', exclude: ['/**/javaee-api-*.jar'], include: ['/**/*.jar'])
compileOnly fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
英文:
I used below trick.
dependencies {
compile fileTree(dir: '../lib', exclude: ['/**/javaee-api-*.jar'], include: ['/**/*.jar'])
compileOnly fileTree(dir: '../lib', include: ['/**/javaee-api-*.jar'])
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论