gpt4 book ai didi

java - Gradle:创建具有依赖项的单个JAR

转载 作者:行者123 更新时间:2023-12-03 03:54:50 24 4
gpt4 key购买 nike

我从一个项目开始就将我们产品的构建从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'

library.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}"

关于java - Gradle:创建具有依赖项的单个JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61604055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com