Gradle:我如何从非java项目发布zip并将其用于java项目中? [英] Gradle: How do I publish a zip from a non-java project and consume it in a java project?

查看:199
本文介绍了Gradle:我如何从非java项目发布zip并将其用于java项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多项目设置。我创建了一个非java项目,其工件是一个zip文件,我将在另一个项目中解压缩。所以这个想法如下所示:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' ----------
apply plugin:'base'

任务doZip(类型:Zip){...}

任务构建(dependsOn:doZip)<< {
}

artifacts {
archives dozip
}


some-java-project
build。 gradle
------------
apply plugin:'war'
configurations {
includeContent //这是一个自定义配置
}
dependency {
includeContent项目(':my-non-java-project')
}

任务expandContent(类型:Copy){
/ /这里是我想要获取所有文件
//属于'includeContent'配置
// //但这总是变成空的。不知道如何将
//非java内容发布到本地存储库(groovy可以理解)
}

所以,我的问题是,如何将非java项目的构件发布到groovy的内部存储库,以便我可以在另一个基于java的项目中进行拾取? 解决方案

的http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/FileCollection.htmlrel =noreferrer> FileCollection :my -non-java-project:dozip 任务输出:

  project(:my-non- java-project)。tasks.getByName(doZip).outputs.files 

请注意, 存档配置是由Java插件添加的,而不是Base plu杜松子酒。但是您仍然可以在 my-non-java-project 中定义一个自定义配置,并使用您的OP中的代码添加工件:

  //在my-non-java-project / build.gradle中
配置{
存档
}
artifacts {
archives dozip
}

然后你就可以通过任务输出配置,像这样(再次,快速和肮脏):

  //在some-java-project / build中。 gradle 
project(:my-non-java-project)。configurations.archives.artifacts.files

请注意,您可以使用 zipTree



如果您需要实际发布 my-non-java-project ,你可以在这里阅读


I have a multi-project setup. I created a non-java project whose artifact is a zip file that I will unzip in another project. So the idea is as below

my-non-java-project
  build.gradle
  ------------
    apply plugin: 'base'

    task doZip(type:Zip) { ... }

    task build(dependsOn: doZip) << {
    }

    artifacts {
      archives doZip
    }


some-java-project
  build.gradle
  ------------
    apply plugin: 'war'
    configurations {
      includeContent // This is a custom configuration
    }
    dependency {
      includeContent project(':my-non-java-project')
    }

    task expandContent(type:Copy) {
      // Here is where I would like get hold of the all the files
      // belonging to the 'includeContent' configuration
      // But this is always turning out to be empty. Not sure how do I publish
      // non-java content to the local repository (as understood by groovy)
    }

So, my question is, how do I publish the artifacts of a non-java project to the internal repository of groovy such that I can pick it up at another java-based project?

解决方案

Not exactly sure what you're after, but here's a quick-and-dirty way to get access to the FileCollection of the :my-non-java-project:doZip task outputs:

project(":my-non-java-project").tasks.getByName("doZip").outputs.files

Note that the archives configuration is added by the Java plugin, not the Base plugin. But you can still define a custom configuration in my-non-java-project and add the artifact to it with the code in your OP:

//in my-non-java-project/build.gradle
configurations {
    archives
}
artifacts {
    archives doZip
}

Then you can access the task outputs via the configuration, like so (again, quick-and-dirty):

//in some-java-project/build.gradle
project(":my-non-java-project").configurations.archives.artifacts.files

Note that you can expand the content of your zip file using zipTree.

If you need to actually publish the zip produced by my-non-java-project, you can read about that here.

这篇关于Gradle:我如何从非java项目发布zip并将其用于java项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆