简体   繁体   English

Gradle失败了项目依赖项,因为它无法将jar文件添加到自身

[英]Gradle is failing a project dependency as it cannot add jar file to itself

I am creating a new gradle build for some existing code. 我正在为一些现有代码创建一个新的gradle构建。 I am looking at the first two projects - common and database. 我正在看前两个项目 - 普通和数据库。 database is dependent on common. 数据库取决于共同点。

Both have a shared list of jar files which is being correctly added as a dependency from a shared root build.gradle. 两者都有一个jar文件的共享列表,它正在从共享的根build.gradle中正确添加为依赖项。 The common code is compiled correctly and without problem. 公共代码编译正确且没有问题。

The issue I have is adding a dependency to common from database causes gradle to try and add the common.jar file to itself, filling up the hard drive until it ultimately crashes. 我遇到的问题是从数据库添加对common的依赖导致gradle尝试将common.jar文件添加到自身,填满硬盘驱动器直到它最终崩溃。

I have tried setting the dependency in a build.gradle in the database folder, and adding it in the root build.gradle using project(":database"), and both have the same problem. 我已经尝试在数据库文件夹中的build.gradle中设置依赖项,并使用项目(“:database”)在根build.gradle中添加它,并且两者都有相同的问题。

I cannot change the "src" folder as these are existing projects, and the application that uses them understands the given structure: common common\\src common\\src\\common common\\src\\common\\MyFile.java database database\\src database\\src\\database database\\src\\database\\MyDatabase.java database\\src\\database\\example\\DatabaseExample.java etc 我无法更改“src”文件夹,因为这些是现有项目,并且使用它们的应用程序理解给定的结构:常见的常见\\ src common \\ src \\ common common \\ src \\ common \\ MyFile.java数据库数据库\\ src数据库\\ src \\ database database \\ src \\ database \\ MyDatabase.java database \\ src \\ database \\ example \\ DatabaseExample.java等

subprojects {

    apply plugin: "java"

    sourceSets {
        main {
            java.srcDirs = files("src")
            java.outputDir = file("build")
        }
    } 

    dependencies {
        implementation files(
            fileTree("${binDir}") { include("java*.jar") },
            "${binDir}/blah/blah_core.jar",
            <etc - none of them are common.jar>
        )
    }
}

project(":database") {
    dependencies {
        implementation project(":common")
    }
}

12:39:38.649 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 12:39:38.649 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]失败:构建因异常而失败。 12:39:38.650 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 12:39:38.651 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 12:39:38.651 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':common:jar'. 12:39:38.650 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 12:39:38.651 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *出了什么问题:12:39:38.651 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]任务':common:jar'的执行失败。 12:39:38.651 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not add file 'C:\\Code\\Git\\gradle\\common\\build\\libs\\common.jar' to ZIP 'C:\\Code\\Git\\gradle\\common\\build\\libs\\common.jar'. 12:39:38.651 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]>无法将文件'C:\\ Code \\ Git \\ gradle \\ common \\ build \\ libs \\ common.jar'添加到ZIP'C:\\代码\\的Git \\ gradle这个\\ COMMON \\编译\\库\\ common.jar”。

For anyone in the future; 对于未来的任何人; the issue was 问题是

            java.outputDir = file("build")

Removing this and the build started working as expected 删除它和构建开始按预期工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM