【发布时间】:2021-07-06 00:56:03
【问题描述】:
我们有具有这种结构的项目
common - 模块 src - 弹簧启动 工人 - 模块
在工作模块中,我们有这样配置的 build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.worker.worker.EntryPoint'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
destinationDir(new File(projectDir.parent,"\\libs\\worker\\"))
with jar
}
dependencies {
compile project(':jTransfer')
compile project(':datamasking')
compile project(':common')
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'mysql:mysql-connector-java:8.0.19'
implementation 'com.microsoft.sqlserver:mssql-jdbc'
implementation 'com.microsoft.sqlserver:mssql-jdbc:8.4.1.jre8'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
当我运行任务 fatJar sqlserver:mssql-jdbc 时丢失。我试图在这部分打印 来自 {configuration.compile.collect { it.isDirectory() 的代码? it : zipTree(it) } } 和 "it" 从未被引用到 sqlserver jdbc jar。
由于工作模块包含公共模块“compile project(':common')”,我试图将依赖项放在公共模块中。当我这样做时,在控制台中打印出 sqlserver:mssql 并且当我进入 jar 存档 sqlserver:mssql jar 时,问题是当我运行 java -jar worker 时,输出无法加载主类: ...
同样的事情也发生在 Tika 库中。所以我不确定它是否与这些 jars 有关,或者我正在使用这些模块做一些关键的事情,也许有一些冲突
我试过用这个
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
发生的事情是我的 jar 找不到主类,但是当我进入 jar 存档时。我去我的 com.worker... 我看到有两个 EntryPoint.class 文件。
所以简而言之,当我不使用这两行代码时,我的 jar 可以启动,它有一个 EntryPoint.class 文件,但是缺少 jdbc jar 库
【问题讨论】: