【问题标题】:Gradle: Consuming a Zip artifact from an included buildGradle:从包含的构建中使用 Zip 工件
【发布时间】:2023-01-29 05:44:59
【问题描述】:

我有一个生成 zip 文件的项目和另一个使用后者的项目。它一定以某种方式工作,类似于下面的方式,但是,我还不能做到。我也不真正了解如何仅通过包含的构建将依赖关系连接在一起。

这是我试过的:

zip-producing-project/settings.gradle:

rootProject.name = 'zip-producing-project'

zip-producing-project/build.gradle:

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

task createZip(type: Zip) {
    from 'src/main/resources'
    include '*'
    archiveName 'zip-producing-project.zip'
}

artifacts {
    archives file('build/distributions/zip-producing-project.zip') // not sure "archives" is the right configuration
}

tasks.build.dependsOn "createZip"

zip-consuming-project/settings.gradle:

rootProject.name = 'zip-consuming-project'
includeBuild '../zip-producing-project'

zip-consuming-project/build.gradle:

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

dependencies {
    archives 'org.example:zip-producing-project:1.0-SNAPSHOT@zip' // is that correct?
}

task unzip(type: Copy) {

    configurations.archives.resolve().forEach {
        if (it.name.endsWith(".zip")) {
            from zipTree(it)
        }
    }

    into "${project.buildDir}"
}

调用gradle clean build 产生:

FAILURE: Build failed with an exception.

* Where:
Build file 'zip-consuming-project\build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'zip-consuming-project'.
> Could not resolve all files for configuration ':archives'.
   > Could not find zip-producing-project.zip (project :zip-producing-project)

我如何让它工作,我。 e.让zip-consuming-project找到神器zip-producing-project.zip

【问题讨论】:

    标签: gradle


    【解决方案1】:

    我找到了解决方法,但我对此并不满意。

    包含构建(发布者):

    artifacts {
        add("archives", tasks.register<Zip>("publishSomething") {
            archiveClassifier.set("something")
            from(...)
        })
    }
    

    包括构建(消费者)

    val extractSomething = tasks.register<Copy>("extractSomething") {
        dependsOn(gradle.includedBuild("included-name").task(":publishSomething"))
        // This is the hacky part, ideally this would be simply `from(gradle.iB().t())`
        from(zipTree(rootProject.file("some/included-name/build/distributions/included-name-something.zip")))
        into(layout.buildDirectory.dir("extracted-something"))
    }
    tasks.named("compileKotlin").configure { dependsOn(extractSomething) }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多