Gradle: 创建一个带有依赖项的 JAR
Gradle: create a single JAR with dependencies
我正在将我们的产品构建从 Ant 迁移到 Gradle,从单个项目开始并遇到以下错误:
> Could not resolve all files for configuration ':Shared:serverbase:compileClasspath'.
> Could not find guava:guava:23.3-jre.
Searched in the following locations:
- https://jcenter.bintray.com/guava/guava/23.3-jre/guava-23.3-jre.pom
- file:/F:/pros/X/java/guava/guava-23.3-jre.xml
Required by:
project :Shared:serverbase
为什么它正在寻找 xml 文件而不是 jar?
这是我的文件:
build.gradle 在项目的根目录中:
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' // gwt compiler plugin
}
}
allprojects {
apply from: rootProject.file('libraries.gradle')
repositories {
jcenter()
ivy {
url "file://${rootProject.projectDir}/ThirdParty/java/"
patternLayout {
artifact "[organization]/[module](-[revision])(.[ext])"
}
}
}
}
subprojects {
apply plugin: 'java-library'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
compileJava.options.debugOptions.debugLevel = "lines,vars,source"
compileJava.options.compilerArgs += ["-nowarn"]
compileJava.options.debug = true
}
此单个项目的build.gradle:
sourceSets.main.java.srcDirs = ['src']
dependencies {
implementation "guava:guava:${guavaVersion}"
implementation "slf4j:jul-to-slf4j:${slf4jVersion}"
implementation "logback:logback-classic:${logbackVersion}"
}
jar {
manifest {
attributes 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' ')
}
}
settings.gradle:
rootProject.name = 'X'
include 'Shared:serverbase'
libraries.gradle:
ext {
...
guavaVersion = '23.3-jre'
...
}
(删除了一些内容)
如果我将文件依赖项添加到 build.gradle 作为本地文件 (How to add local .jar file dependency to build.gradle file?)
implementation files("guava-${guavaVersion}.jar")
我遇到了很多错误,例如“错误:包 org.slf4j 不存在”,因此似乎根本不满足依赖关系。
结果应该是带有编译源的单个 jar。
本人是gradle新手,请见谅
您的 Guava 依赖项不正确。
更改自:
implementation "guava:guava:${guavaVersion}"
收件人:
implementation "com.google.guava:guava:${guavaVersion}"
我正在将我们的产品构建从 Ant 迁移到 Gradle,从单个项目开始并遇到以下错误:
> Could not resolve all files for configuration ':Shared:serverbase:compileClasspath'.
> Could not find guava:guava:23.3-jre.
Searched in the following locations:
- https://jcenter.bintray.com/guava/guava/23.3-jre/guava-23.3-jre.pom
- file:/F:/pros/X/java/guava/guava-23.3-jre.xml
Required by:
project :Shared:serverbase
为什么它正在寻找 xml 文件而不是 jar?
这是我的文件: build.gradle 在项目的根目录中:
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' // gwt compiler plugin
}
}
allprojects {
apply from: rootProject.file('libraries.gradle')
repositories {
jcenter()
ivy {
url "file://${rootProject.projectDir}/ThirdParty/java/"
patternLayout {
artifact "[organization]/[module](-[revision])(.[ext])"
}
}
}
}
subprojects {
apply plugin: 'java-library'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
compileJava.options.debugOptions.debugLevel = "lines,vars,source"
compileJava.options.compilerArgs += ["-nowarn"]
compileJava.options.debug = true
}
此单个项目的build.gradle:
sourceSets.main.java.srcDirs = ['src']
dependencies {
implementation "guava:guava:${guavaVersion}"
implementation "slf4j:jul-to-slf4j:${slf4jVersion}"
implementation "logback:logback-classic:${logbackVersion}"
}
jar {
manifest {
attributes 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' ')
}
}
settings.gradle:
rootProject.name = 'X'
include 'Shared:serverbase'
libraries.gradle:
ext {
...
guavaVersion = '23.3-jre'
...
}
(删除了一些内容)
如果我将文件依赖项添加到 build.gradle 作为本地文件 (How to add local .jar file dependency to build.gradle file?)
implementation files("guava-${guavaVersion}.jar")
我遇到了很多错误,例如“错误:包 org.slf4j 不存在”,因此似乎根本不满足依赖关系。 结果应该是带有编译源的单个 jar。
本人是gradle新手,请见谅
您的 Guava 依赖项不正确。
更改自:
implementation "guava:guava:${guavaVersion}"
收件人:
implementation "com.google.guava:guava:${guavaVersion}"