Gradle Archive Tasks: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.AbstractArchiveTask.html =Internal= * Gradle Task =Overview=...")
 
 
(2 intermediate revisions by the same user not shown)
Line 33: Line 33:


<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
task myJar(type: Jar) {
task srcJar(type: Jar) {
   ....
   from sourceSets.main.allJava
}
</syntaxhighlight>
 
A task that is used in a publishing process and builds a Java sources JAR. It assumes that the sources from different sub-projects have been collected in root's ./build/api-sources by other tasks.
 
<syntaxhighlight lang='groovy'>
task apiSources(type: Jar) {
 
    baseName = 'blue-api'
    classifier = 'sources'
    destinationDir = buildDir
    from buildDir.path + "/api-sources"
}
}
</syntaxhighlight>
</syntaxhighlight>
A parent project task that collects in a JAR all sources from all sub-projects. <font color=darkgray>Replace with something more concise, if I can figure out how.</font>


<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
task srcJar(type: Jar) {
task allSourcesFromAllSubprojects(type: Jar) {
  from sourceSets.main.allJava
 
    List<String> locs = new ArrayList<>();
    subprojects { locs.add(it.name + "/src/main/java") }
    from locs.toArray()
}
}
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 23:59, 21 May 2018

External

Internal

Overview

Zip

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Zip.html

Zip assembles a ZIP archive. The default is to compress the content of the ZIP.

task dist(type: Zip) {
    dependsOn spiJar
    from 'src/dist'
    into('libs') {
        from spiJar.archivePath
        from configurations.runtime
    }
}

Jar

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html

Jar assembles a JAR archive.

task srcJar(type: Jar) {
   from sourceSets.main.allJava
}

A task that is used in a publishing process and builds a Java sources JAR. It assumes that the sources from different sub-projects have been collected in root's ./build/api-sources by other tasks.

task apiSources(type: Jar) {

    baseName = 'blue-api'
    classifier = 'sources'
    destinationDir = buildDir
    from buildDir.path + "/api-sources"
}

A parent project task that collects in a JAR all sources from all sub-projects. Replace with something more concise, if I can figure out how.

task allSourcesFromAllSubprojects(type: Jar) {

    List<String> locs = new ArrayList<>();
    subprojects { locs.add(it.name + "/src/main/java") }
    from locs.toArray()
}