Using the JAR files created with “gradle build” command throws run time exceptions


(Meikanda Nayanar) #1

Hi,

I am using gradle-3.0. The OS is Windows 10

I have a java library developed with Gradle plugin in Eclipse. Now when I export JAR files from Eclipse everything is working as expected. But when I create JAR files with “gardle build” command in command prompt then I get exceptions at run time while using the created jar file in samples. The below is the gradel.build file

I get the below exception when I run the sample with the created JAR

Exception in thread “main” java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lcom.MyNamespace.MyType;

apply plugin: 'java'

jar {
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    manifest {
        attributes 'Implementation-Title': 'ndeploy',
            'Implementation-Version': '1.0.0',
            'Built-By': System.getProperty('user.name'),
            'Built-Date': new Date(),
            'Built-JDK': System.getProperty('java.version'),
    }
}

**I do not need an executable Jar so I did not mentioned the “Main-Class” attribute in Jar task. **
After executing the “gradle build” command I am getting the Jar files from “build\libs” folder. Also I found the resources I used in the library are not shipped in the Jar file. But this is different from the run time exceptions I am reporting in this thread.

Any help will be appreciated.
Thanks,
Meikandan