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
I think that using uberjar will fix your problem. It worked with similar case for me.
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.
Related
Trying out to use ObjectBox as java desktop database. However after following the documentation on the web site https://docs.objectbox.io/java-desktop-apps its not working. No MyObjectBox found error.
I am using eclipse ide Version: 2020-09 (4.17.0), Gradle: gradle-6.7.1
ObjectBox seems not creating the model automatically after build (no model folder generated). I have created the class using the Entity annotation, build the project eclipse, nothing happens. Anyone any ideas?
Works in android but not desktop. As i am not familiar with gradle project in eclipse. the following is the build file
buildscript {
ext.objectboxVersion = '2.8.1'
repositories {
jcenter()
}
dependencies {
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
}
}
apply plugin: 'java-library'
apply plugin: 'io.objectbox'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
repositories {
jcenter()
}
dependencies {
implementation "io.objectbox:objectbox-linux:$objectboxVersion"
implementation "io.objectbox:objectbox-macos:$objectboxVersion"
implementation "io.objectbox:objectbox-windows:$objectboxVersion"
}
apply plugin: 'io.objectbox'
dependencies {
implementation "io.objectbox:objectbox-java:$objectboxVersion"
annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"
}
apply plugin: 'io.objectbox'
Doing apply plugin: 'io.objectbox' three times does not look good. Once is enough. Please check the ObjectBox Java examples for a working setup. In your case have a closer look at the java-main example for standalone Java applications.
This is the basic structure with ... where I left out the details (check the full build.gradle file from the example):
buildscript {
...
}
apply plugin: 'java'
apply plugin: 'application'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
mainClassName = "io.objectbox.example.Main"
dependencies {
...
}
// Apply plugin after dependencies block so they are not overwritten.
apply plugin: 'io.objectbox'
Maybe checkout the example and start from there?
I am using IntelliJ and gradle to create a multi-module spring project as shown below.
With the following build.gradle in the root folder, I have the following settings below. When invoked gradle build, a jar gets created in build/libs, however executing that jar I get the error message:
**Error: Could not find or load main class com.connect.configuration.ConnectApplication
** When running the application without building via: gradle bootRun -- the application loads up correctly. However, executing the jar file after building the project, produces the error and the jar prints out the following: using
jar -tf myJar.jar
META-INF/
META-INF/MANIFEST.MF
plugins {
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
subprojects {
group = 'com.connect.connect'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
targetCompatibility = 1.9
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE")
}
}
}
settings.gradle
include 'connect-common'
include 'connect-ui'
include 'connect-services'
include 'connect-application'
include 'connect-configuration'
I have a gradle spring java project setup, after weeks of it working, Idea suddenly thinks it is an android project, keeps asking me for Android SDK, after deleting .gradle and out/ folders and setting JDK in settings, it compiles and starts, but doesn't copy application.properties file that is required to run the app. Tried restarting, deleting .gradle, .idea, and any other output folder that I could find, but it seems like the only solution that temporarily helps is to clone the repository to a new folder. My suspicion is that I have something in my gradle file that tricks idea to think it's android, but couldn't find anything.
My build.gradle
import org.springframework.boot.gradle.plugin.SpringBootPlugin
buildscript {
ext {
springVersion = "4.3.12.RELEASE"
springBootVersion = '2.1.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.ebean:ebean-gradle-plugin:11.34.1")
}
}
apply plugin: SpringBootPlugin
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.ebean'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-websocket:${springBootVersion}")
implementation("org.mindrot:jbcrypt:0.3m")
implementation('io.jsonwebtoken:jjwt-api:0.10.5')
runtime "io.jsonwebtoken:jjwt-impl:0.10.5", "io.jsonwebtoken:jjwt-jackson:0.10.5"
implementation("org.springframework:spring-jdbc:${springVersion}")
implementation("org.apache.logging.log4j:log4j-core:2.11.1")
implementation("org.postgresql:postgresql:42.2.5")
implementation("org.apache.tomcat:tomcat-jdbc:9.0.8")
implementation("io.ebean:ebean:11.36.1")
implementation("io.ebean:ebean-agent:11.11.1")
implementation("io.ebean:ebean-spring-txn:11.10.4")
testImplementation("junit:junit:'4.+")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
Clean IDE project specific files and regenerate them with
./gradlew cleanIdea idea
Then try to import project again.
I have this build.gradle file
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("net.serenity-bdd:serenity-gradle-plugin:1.4.0")
}
}
dependencies {
testCompile('net.serenity-bdd:serenity-core:1.4.0')
testCompile('net.serenity-bdd:serenity-junit:1.4.0')
testCompile('junit:junit:4.12')
testCompile('org.assertj:assertj-core:1.7.0')
testCompile('org.slf4j:slf4j-simple:1.7.7')
}
gradle.startParameter.continueOnFailure = true
It loads serenity libraries to the project BUT some classes are not visible when compile:
PageObject class is not visible
but it truly exists in External libs:
Class in the libs
What should I do to make it be visible in test classes and page object classes?
Also when I import manually by entering full path to the library then gradle runner does not see those classes anyway.
Issue is resolved. Wrong compile scope was chosen. Need to be compile not testCompile.
I am new to gradle.
I am building a project using gradle.
It build successfully without any error. While running the build jar file it is giving classNotFoundException.
I am building a simple spring project from spring.io
However question look similar to this but, could not find a solution. Please help.
edit: This is how my build.gradle looks
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
startScripts {
mainClassName = 'Application'
}
springBoot {
mainClass = "Application"
}
You'll need to start the application with the generated start scripts. They will automatically take care of setting up the proper classpath.