【问题标题】:Gradle: create a single JAR with dependenciesGradle:创建具有依赖项的单个 JAR
【发布时间】:2020-08-19 13:51:28
【问题描述】:

我正在将我们的产品构建从 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(' ')
    }        

}

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新手,请见谅。

【问题讨论】:

    标签: java gradle build ant


    【解决方案1】:

    您的 Guava 依赖项不正确。

    更改自:

    implementation "guava:guava:${guavaVersion}"
    

    收件人:

    implementation "com.google.guava:guava:${guavaVersion}"
    

    【讨论】:

      猜你喜欢
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-11
      • 2015-02-01
      • 2021-03-12
      • 1970-01-01
      相关资源
      最近更新 更多