Java Gradle不会在生成操作后导入添加的依赖项
我使用的是SpringBootVersion1.5.12和Gradle5.2.1 我已经在我的项目中添加了Sentry库,如以下文档所述:Java Gradle不会在生成操作后导入添加的依赖项,java,spring-boot,gradle,build,sentry,Java,Spring Boot,Gradle,Build,Sentry,我使用的是SpringBootVersion1.5.12和Gradle5.2.1 我已经在我的项目中添加了Sentry库,如以下文档所述: implementation 'io.sentry:sentry:1.7.23' Gradle在以下位置下载相关文件:\.Gradle\caches\modules-2\files-2.1\io.sentry\sentry\1.7.23 我还可以在IDE的外部库中看到它 然后我在本地环境中配置了它,一切正常,我可以在Sentry dashboard中看到我
implementation 'io.sentry:sentry:1.7.23'
Gradle在以下位置下载相关文件:\.Gradle\caches\modules-2\files-2.1\io.sentry\sentry\1.7.23
我还可以在IDE的外部库中看到它
然后我在本地环境中配置了它,一切正常,我可以在Sentry dashboard中看到我的异常报告
但在那之后,当我想为我的生产环境创建project版本时,构建操作成功结束,但这个新库不在包含myPro.jar和我使用的其他库的文件夹中(这是我名为Distribution
的构建操作的结果),我遇到了一个异常:
Exception in thread "main" java.lang.NoClassDefFoundError: io/sentry/Sentry
at ir.anarestan.ipc.boot.Boot.initSentry(Boot.java:22)
at ir.anarestan.ipc.boot.Boot.main(Boot.java:17)
Caused by: java.lang.ClassNotFoundException: io.sentry.Sentry
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
这是我的build.gradle
文件:
group 'pc-server'
version '0.2.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
<some other dependecies>
implementation 'io.sentry:sentry:1.7.23'
}
apply plugin: 'application'
mainClassName = 'ir.anarestan.ipc.boot.Boot'
jar {
manifest {
attributes 'Main-Class': mainClassName,
'Class-Path': configurations.runtime.files.collect {"$it.name"}.join(' ')
}
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File PC',
'Implementation-Version': version,
'Main-Class': 'ir.anarestan.ipc.boot.Boot'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
ext.distributionDir= "${rootDir}/dist/core"
ext.mainClassName = 'ir.anarestan.ipc.boot.Boot'
jar {
manifest {
attributes("Implementation-Title": project.name,
"Implementation-Version": version,
"Main-Class": mainClassName,
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
destinationDir = file("$distributionDir")
}
task copyLibs(type: Copy){
from configurations.compile
into "$distributionDir"
}
task copyConfig(type: Copy){
from "$projectDir/src/main/resources/"
into "$distributionDir"
}
task distribution(dependsOn: ['copyLibs', 'copyConfig', 'jar']){
}
任何帮助都将不胜感激,这花了我很多时间 你为什么使用1.7版?Sentry Java已经在4.2上了。@BrunoGarcia因为我们在私有服务器上安装了一个Sentry版本,它的文档说客户端版本应该是1.7.23,无论如何你的意见与我的问题无关,我尝试了客户端版本4.3.0,但我的构建操作的结果不包含任何与Sentry相关的jar文件,你对这个问题有什么看法?你使用的是什么版本的岗哨?如果是20.06或更高版本,您可以使用最新版本的JavaSDK(希望能够解决您的问题)。
@SpringBootApplication
@EnableMongoRepositories(basePackages = {"ir.anarestan.ipc.repository.mongodb"})
public class Boot {
public static void main(String[] args) {
SpringApplication.run(Boot.class, args);
Sentry.init();
}
}