Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How do I publish a zip from a non-java project and consume it in a java project?

Tags:

gradle

build

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?

like image 411
Harsha R Avatar asked Aug 28 '13 19:08

Harsha R


People also ask

How do I create a zip file in Gradle?

In Gradle, zip files can be created by using 'type: zip' in the task. In the below example, from is the path of source folder which we want to zip. destinationDir is the path of the destination where the zip file is to be created.

What is source compatibility in Gradle?

According to Gradle documentation: sourceCompatibility is "Java version compatibility to use when compiling Java source." targetCompatibility is "Java version to generate classes for."


1 Answers

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.

like image 142
superEb Avatar answered Oct 04 '22 22:10

superEb