Search code examples
gradlebuild.gradlegradle-shadow-plugin

manifest issue for shadow plugin with gradle


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).

Solution

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