java - Gradle:创建具有依赖项的单个 JAR
问题描述
我正在将我们的产品构建从 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 -files 而不是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(' ')
}
}
设置.gradle:
rootProject.name = 'X'
include 'Shared:serverbase'
图书馆.gradle:
ext {
...
guavaVersion = '23.3-jre'
...
}
(部分内容删减)
如果我将文件依赖项添加到 build.gradle 作为本地文件(如何将本地 .jar 文件依赖项添加到 build.gradle 文件?)
implementation files("guava-${guavaVersion}.jar")
我遇到了很多错误,例如“错误:包 org.slf4j 不存在”,因此似乎根本不满足依赖关系。结果应该是一个带有编译源的 jar。
我是gradle的新手,请原谅我的不悟。
解决方案
您的 Guava 依赖项不正确。
更改自:
implementation "guava:guava:${guavaVersion}"
至:
implementation "com.google.guava:guava:${guavaVersion}"
推荐阅读
- parallel-processing - 嵌套 DO 循环中的文件名 - Fortran
- python - 为什么我在这一行中得到无效的语法----> f.writelines(f'{attrib} = {VIDEO_CHECK.get(index)}\n')
- c# - OpenTK 斜截头体(镜头移位)
- http - 查询 Apple TV 当前播放的媒体信息
- c# - MVC 下拉列表用于多项选择不起作用只是打开完整列表?
- webpack - webpack 中动态导入文本文件
- python-3.x - 基于电阻值的排序表(列表)
- python - Python3 ODBC 执行许多
- github - GitHub:术语:创建拉取请求与打开拉取请求
- mysql - 对表进行大量更新时数据可用性对用户的影响