Gradle: created jar by gradle task bootJar is not working - java

I am creating a spring boot application with the following properties the project is running successfully when I run projects with Gradle bootrun it is running successfully but when i create a jar and deploy its not working here is my build.gradle
I have checked all the versions of my project are same.
Error :Error mapping to ad-hoc class .. At present, only #Result types that are discovered by the domain entity package scanning can be mapped.;
nested exception is org.neo4j.ogm.exception.core.MappingException: Error mapping to ad-hoc class com.vipul.... At present, only #Result types that are discovered by the domain entity package scanning can be mapped
PS: I KNOW ABOUT QUERY RESULT mapping but its working with bootRun but not with bootJar
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
swaggerVersion = '2.5.0'
jacksonVersion = '2.9.2'
projectVersion = "0.0.1"
version = "0.0.1"
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
apply plugin: 'idea'
apply plugin: 'application'
version = "$projectVersion-SNAPSHOT"
sourceCompatibility = 1.8
mainClassName = 'com.vipul.Application'
applicationDefaultJvmArgs = ["-Xdiag"]
repositories {
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
maven{ url "https://repo.spring.io/plugins-release"}
}
task wrapper(type: Wrapper) { gradleVersion = '4.4' }
ext {
springCloudVersion = 'Finchley.RELEASE'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-data-neo4j')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

Try changing springBoot and springCloud versions in your build.gradle
**
springBootVersion='2.0.0.RELEASE'
**
It seems to be problem with spring boot version. springBootVersion = '2.0.5.RELEASE'

Related

Why do I get Gradle configure build error junit5 in IntelliJ?

I created clean project with spring boot initializer and I get configure build error. The message I get is: Could not find org.junit:junit-bom:5.4.0-SNAPSHOT. but in my gradle file I don't have it. What's wrong with it?
buildscript {
ext {
springBootVersion = '2.2.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('org.springframework.security:spring-security-test')
}
You're using a development (snapshot) version of Spring Boot that refers to a development (snapshot) version of JUnit 5, but you have not added JUnit's snapshot repository: https://oss.sonatype.org/content/repositories/snapshots/org/junit/junit-bom/5.4.0-SNAPSHOT/:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
But you'd better use generally available versions.
The Junit dependency comes with "spring-boot-starter-test", it may not be available in your spring version. Try to change the spring version or use a latest version and give it a go.

Gradle, multiproject signing with gpg. Cannot configure the 'publishing' extension after it has been accessed

I have multiproject gradle configuration. I'd like to sign my artifacts before publishing. I do the following:
allprojects {
apply plugin: 'java'
sourceCompatibility = 1.10
}
subprojects {
group 'com.example'
version '1.0.0'
apply plugin: 'maven-publish'
apply plugin: 'signing'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
...
}
test {
useJUnitPlatform()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
signing {
sign publishing.publications.mavenJava
}
}
I get the following error:
Cannot configure the 'publishing' extension after it has been
accessed.
I have no idea what does it mean. I use gradle 4.8.
I have 3 subprojects there.
I ran into the same issue with Gradle 4.9
Apply the signing plugin before the maven-publish.
Hope it helps.
apply plugin: 'signing'
apply plugin: 'maven-publish'

Override Spring Starter Version version in gradle

I would like the maven equivalent of properties in gradle:
<properties>
<spring-batch.version>4.0.0.M2</spring-batch.version>
</properties>
When I added ext['spring-batch.version'] = '4.0.0.M2' in build.gradle, imports are not working.
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext['spring-batch.version'] = '4.0.0.M2'
dependencies {
compile('org.springframework.boot:spring-boot-starter-batch')
compile("org.hsqldb:hsqldb")
}
I also tried to add spring-batch.version=4.0.0.M2 in gradle.properties, but not working also.
It's failing because 4.0.0.M2 isn't in Maven central.
To fix it, add the Spring milestone Maven repository:
repositories {
mavenCentral()
maven {
url "http://repo.spring.io/libs-milestone"
}
}
first I'd use the new plugin mechanis like so:
buildscript {
repositories { mavenCentral() }
}
plugins {
id 'java'
id 'application' // for docker needed the main class in jar manifest
id 'eclipse'
id 'idea'
id 'org.springframework.boot' version '1.5.4.RELEASE' // automagically includes io.spring.dependency-management
}
this should automagically give you the correct version of all org.springframework.boot dependencies, without having to specify them explicitly (so no need to give a version number for spring-batch.
if you'd like to define further project.ext properties, do so like:
ext {
group = 'minimal_cloud_stream_producer'
groupId = 'de.demo'
baseName = 'minimal_cloud_stream_producer'
port = 8080
}
maybe you have to add a dependencyManagement section too, like so
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.5.4.RELEASE'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'
}
}

Gradle build successful, error running jar

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.

Gradle is not downloading Jax RS libraries

I am trying to download and add JaxRS libraries with gradle. Here is the build script:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'jetty'
jar {
baseName = 'rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile('javax.ws.rs:jsr311-api:1.1.1')
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
try with --debug and see the URL it is using to retrieve the dependency. Then use curl or similar tool and see if it is available. If you can't get to it through your browser or curl then networking issue.
Check maven central too, maybe they don't have that version anymore. Just to validate.

Categories