我正在尝试制作一个 MultiProject 项目,其中 1 个被共享(我在下面将其称为 Common)和 3 个其他项目,我只调用了 AB 和 D。我试图让它们编译成“胖 jars”(或所有的 jars其中包含的依赖项)通过 Shadow 插件。
我还想声明我对 gradle 很陌生。我正在使用:IntelliJ IDEA 2021 Gradle 6.8 Java 11
我的项目是这样布置的:
+ /
| build.gradle
| settings.gradle
+ Subproject.A
| build.gradle
+ Subproject.B
| build.gradle
+ Subproject.Common (dependency for A, B, & D)
| build.gradle
+ Subproject.D
| build.gradle
我在所有项目(Common 除外)上遇到的错误是它没有成功运行:compileJava。
当您在项目上运行 :shadowJar 或 :jar 命令时,它会成功完成 Common 项目的任务,然后立即使项目上的 :compileJava 任务失败。
> Task :Subproject.Common:compileJava UP-TO-DATE
> Task :Subproject.Common:processResources UP-TO-DATE
> Task :Subproject.Common:createProperties
> Task :Subproject.Common:classes
> Task :Subproject.Common:jar
> Task :Subproject.A:compileJava FAILED
Z:\IdeaProjects\Project\Subproject.A\src\main\java\subproject\a\Class.java:321: error: package subproject.common does not exist
import subproject.common.Class;
^
我不相信它是影子插件,因为它发生在 :shadowJar 甚至运行之前。我尝试过使缓存无效以及重新导入和重做 build.gradle 文件,但没有成功。
我不确定格式化 build.gradle 文件的最佳方式,但在朋友的一些指导下,这就是它们的样子。
/build.gradle
plugins {
id 'java'
id 'com.palantir.git-version' version '0.12.1'
id "com.github.johnrengelman.shadow" version "5.2.0"
}
group 'project'
version '1'
subprojects {
apply plugin: 'java'
apply plugin: 'com.palantir.git-version'
apply plugin: 'com.github.johnrengelman.shadow'
//bumping the "version" (build) number and giving a lot of versioning information
def verNumFile = new File("$projectDir/verNum.properties")
Properties verNumProp = new Properties()
if (!verNumFile.exists()) {
verNumFile.getParentFile().mkdirs()
verNumFile.createNewFile()
verNumProp['ver'] = '0'
verNumFile.withWriter { w ->
verNumProp.store w, null
}
} else {
verNumProp.load(new FileReader(verNumFile))
}
def currVerNum = Integer.parseInt(verNumProp['ver'].toString())
version = "b" + currVerNum + ".h" + gitVersion()
task createProperties(dependsOn: processResources) {
doLast {
Properties verProp = new Properties()
def verFile = new File("$buildDir/resources/main/version.properties")
if (!verFile.exists()) {
verFile.getParentFile().mkdirs()
verFile.createNewFile()
} else {
verProp.load(new FileReader(verFile))
}
currVerNum++
verNumProp['ver'] = (currVerNum).toString()
verNumFile.withWriter { w ->
verNumProp.store w, null
}
verFile.withWriter { w ->
verProp['name'] = project.name
verProp['group'] = project.group
verProp['version'] = project.version = "b" + currVerNum + " h" + gitVersion()
verProp['versionNumber'] = currVerNum.toString()
def details = versionDetails()
verProp['lastTag'] = details.lastTag
verProp['commitDistance'] = details.commitDistance.toString()
verProp['gitHash'] = details.gitHash
verProp['gitHashFull'] = details.gitHashFull
verProp['branchName'] = details.branchName
verProp['isCleanTag'] = details.isCleanTag.toString()
verProp.store w, null
}
}
}
classes {
dependsOn createProperties
}
repositories {
mavenCentral()
maven {
url 'https://papermc.io/repo/repository/maven-public/'
}
}
dependencies {
compile 'com.google.api-client:google-api-client:1.30.4'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.30.6'
compile 'com.google.apis:google-api-services-sheets:v4-rev581-1.25.0'
compile 'com.squareup.okhttp3:okhttp:4.9.0'
compile 'redis.clients:jedis:3.3.0'
compile 'org.mongodb:mongodb-driver:3.6.3'
compile 'com.google.code.gson:gson:2.8.6'
compile 'commons-io:commons-io:2.8.0'
compileOnly 'io.github.waterfallmc:waterfall-api:1.16-R0.4-SNAPSHOT'
if(!project.name.endsWith("Common"))
compile project(":Subproject.Common")
}
jar {
manifest {
attributes(
"Main-Class": "Bootstrap"
)
}
}
}
/settings.gradle
rootProject.name = 'Project'
include ':Subproject.A'
include ':Subproject.B'
include ':Subproject.Common'
include ':Subproject.D'
/Subproject.A/build.gradle , /Subproject.Common/build.gradle & /Subproject.D/build.gradle
plugins {
id 'java'
}
/Subproject.B/build.gradle
plugins {
id 'java'
}
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.docker-java:docker-java-core:3.2.10'
compile 'com.github.docker-java:docker-java-transport-httpclient5:3.2.10'
compile 'com.github.robinbraemer:cloudflareapi:1.4.0'
}
感谢您提供的任何帮助/指导。(即使只是为了整个gradle,因为我还在学习)