0

I am using gradle v3.4 & shadow plugin v1.2.4. I am publishing a jar file to my local maven repo using the following inside my build.gradle file

mainClassName = 'some.thing.SomeClient'
    jar {
        manifest {
            attributes(
                    'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                    // 'Main-Class': 'some.thing.SomeClient'
            )
        }
    }

    shadowJar {
        baseName = 'commons-java'
        classifier = null
        version = '0.0.1-SNAPSHOT'
    }

    artifacts {
        archives shadowJar
    }

    jar.dependsOn shadowJar

After publishing, I try to use this dependency inside another project as follows but get the error copied below when I run gradle build

 /**
 * jar/shadow jar (shadow jar extends jar task to create fat jar)
 */
jar {
    manifest {
        attributes(
                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                //'Main-Class': 'some.thing.SomeClient'
        )
    }
}

shadowJar {
    baseName = 'something-java-client'
    classifier = null
    version = '0.0.1-SNAPSHOT'
}

artifacts {
    archives shadowJar
}

jar.dependsOn shadowJar

error

The value of a manifest attribute must not be null (Key=Main-Class).
ali haider
  • 19,175
  • 17
  • 80
  • 149
  • I have published the jar file with and without a mainclassname (i checked the manifest file in the jar to confirm as well). I still get the same error regardless of whichever option I chose for the published jar file – ali haider May 10 '17 at 17:04
  • I had the mainClassName attribute in my gradle.settings - removing it from gradle.settings fixed the issue – ali haider May 10 '17 at 17:19

2 Answers2

1

The issue was caused by the mainClassName attribute in gradle.properties leading to the exception. Removing it from gradle.properties fixed the issue.

ali haider
  • 19,175
  • 17
  • 80
  • 149
1

It also could be that the mainClassName is set after the plugin is applied, which seems to be a known issue. The quick and dirty solution is to set the property before applying the plugin, like this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
    }
}

plugins {
    id "application"
}

mainClassName = 'some.thing.SomeClient'

apply plugin: 'com.github.johnrengelman.shadow'

// ...
Guillermo Gutiérrez
  • 17,273
  • 17
  • 89
  • 116