Remove default Jar artifact

Hi all,

I’m bit confused about behaviour of my gradle build. I’m trying to create simple build file which would do following (as experiment): 1, take configuration folder 2, package it into Zip format 3, upload Zip to nexus

However, I got stuck on default Jar artifact which gets uploaded together with my Zip. Is there a way how to tell gradle, that all I really want to do, is simply upload Zip and nothing else? (I have no Jar task defined in my build, only Zip)

apply plugin: 'java'
  defaultTasks 'createZip'
  def resultZipName = 'myzip'
def resultZipDir = '/zip'
  repositories {
    mavenCentral()
}
  dependencies {
    // for testing transitive dependencies
    compile 'org.hibernate:hibernate-core:4.1.7.Final'
}
  task createZip(type: Zip) {
    from '/'
    include 'conf/**'
    include 'build.gradle'
    setBaseName(resultZipName)
    destinationDir = file(resultZipDir)
}
  artifacts {
    archives createZip
}
  task cleanZip(type: Delete) {
    delete resultZipDir
}
  uploadArchives {
    repositories {
        maven {
            credentials {
                username 'admin'
                password 'admin123'
            }
            name = 'nexus-local'
            url = 'http://localhost:8081/nexus/content/repositories/snapshots/'
        }
   }
}
  Results in following:
:createZip
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:uploadArchives
Upload to http://localhost:8081/nexus/content/repositories/snapshots//gradle/unspecified/Gradle-unspecified.jar
Upload to http://localhost:8081/nexus/content/repositories/snapshots//gradle/unspecified/Gradle-unspecified.jar.sha1
Upload to http://localhost:8081/nexus/content/repositories/snapshots//gradle/unspecified/gradle-zip-unspecified.zip
Upload to http://localhost:8081/nexus/content/repositories/snapshots//gradle/unspecified/gradle-zip-unspecified.zip.sha1
Upload to http://localhost:8081/nexus/content/repositories/snapshots//gradle/unspecified/ivy-unspecified.xml
Upload to http://localhost:8081/nexus/content/repositories/snapshots//gradle/unspecified/ivy-unspecified.xml.sha1

Well if you apply the java plugin, Gradle assumes you have some java source files that you would like to compile, package and upload as a jar archive. If you only need to package some configuration files, then you could apply just the base plugin to get the ‘archives’ configuration and ‘uploadArchives’ task.

Many thanks for quick answer Detelin. I managed to bypass applying java plugin, and therefore I was able to specify only ZIP archive as build artifact. Following build.gradle file uploads only single Zip archive specified for archives configuration.

apply plugin: 'maven'
  def resultZipName = 'myGradleModule'
def resultZipDir = '/myZipDir'
  group = 'gradle.test'
version = '1.0'
  uploadArchives {
    repositories {
        maven {
            credentials {
                username 'admin'
                password 'admin123'
            }
            name = 'nexus-local'
            url = 'http://localhost:8081/nexus/content/repositories/snapshots/'
        }
    }
}
  task createZip(type: Zip) {
    from '/'
    include 'conf/**'
    include 'build.gradle'
    include 'settings.gradle'
    setBaseName(resultZipName)
    destinationDir = file(resultZipDir)
}
  artifacts {
    archives createZip
}

Please note, you also need to specify settings.gradle file in your build directory, if you wish to name your artifact differently from directory name, your build file is in. settings.gradle:

rootProject.name = "zipArtifact"