1

I am using gradle-3.0. The OS is Windows 10. I do not have any dependent projects.

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.
  • In addition, I found the resources I used in the java library are not shipped in the Jar file. But this is different from the run time exceptions I like to discuss in this thread.
  • The same kind of exceptions happen when I try to create jar from the jar cvf jarname.jar * command without gradle.

So what am I going wrong?

Any help will be appreciated.

IMK
  • 654
  • 9
  • 15

0 Answers0