2

I have groovy application that i want to pack in executable jar with gradle. The problem is when the jar is done i have error: Could not find or load main class . Here is my build.gradle:

group 'com.demo'
version '1.0-SNAPSHOT'

 apply plugin: 'groovy'
 apply plugin: 'java'
 apply plugin: 'idea'
 apply plugin:'application'
 mainClassName = 'com.demo.App'


 buildscript {
      repositories {
          mavenCentral()
      }
      dependencies {}
 }

  repositories {
   mavenCentral()
  }
  // java version dependency
   sourceCompatibility = 1.8
   targetCompatibility = 1.8

  jar {
baseName = 'cim-configurator'
version =  '0.1.0'
manifest {
    attributes("Build-Time": new Date().format("yyyy-MM-dd HH:mm:ss"),
            "Build-Jdk": System.getProperty("java.version"),
            "Built-By": System.getProperty("user.name"),
            "Created-By": "Gradle",
            "Main-Class": "com.demo.App"
    )
  }
}

Here is the file hierarchy:

com.demo
   ActiveMq
   App
   Database
   Rbac
   Run.groovy
   Service
Bambus
  • 1,493
  • 1
  • 15
  • 32
  • How do you get this error ? From which command ? – ToYonos Sep 27 '18 at 09:06
  • When i try to start the jar with java -jar – Bambus Sep 27 '18 at 09:09
  • Please also add the file hierarchy. – cfrick Sep 27 '18 at 10:06
  • @cfrick I edited the question – Bambus Sep 27 '18 at 10:34
  • My guess here is, that you lack the dependency for `groovy` (e.g. `groovy-all`) and the error here actually hides that fact it can not see `GObject` and friends. I am yet not really convinced what files here are groovy and what are java and what are the sources actually (from your partial tree). So i am surporsed this even built. – cfrick Sep 27 '18 at 11:49

2 Answers2

1

I think that using uberjar will fix your problem. It worked with similar case for me.

xmlParser
  • 1,903
  • 4
  • 19
  • 48
0

I had this exact same problem in a Groovy & Gradle project. This is the answer that fixed this problem.

TL;DR

Use the Shadow-jar plugin by adding the following plugin to your plugins block in build.gradle:

plugins {
    id 'com.github.johnrengelman.shadow' version '5.0.0'
}

Then run ./gradlew shadowJar

You'll get a jar file emailer-all.jar, which can be run.

SGT Grumpy Pants
  • 4,118
  • 4
  • 42
  • 64