Execution failed for task ':compileJava' - java

I am trying to build a Spring cloud application that provides details of a Customer and the order history he/she has made in the past via gradle. When I am executing the build and clean task, I am unable to obtain the target jar file because of this error.
Execution failed for task ':compileJava'.
This is the message shown in the ExceptionStackTrace of the error log.
org.gradle.tooling.BuildException: Could not execute build using Gradle installation 'C:\gradle\gradle-3.4.1'.
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:51)
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:41)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
Below is my build.gradle file.
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'yBayApplication'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-turbine:1.2.3.RELEASE')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-hystrix-dashboard')
compile('org.springframework.cloud:spring-cloud-starter-hystrix')
compile('org.springframework.cloud:spring-cloud-starter-feign')
compile('org.springframework.cloud:spring-cloud-starter-eureka:1.2.3.RELEASE')
compile('org.springframework.cloud:spring-cloud-starter-ribbon')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.BUILD-SNAPSHOT"
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
I have checked the Java version which gradle uses and it points to the right directory C:\Program Files (x86)\Java\jdk1.8.0_121 and I have also included the gradle.properties file in the project to be double sure that it fetches only the Java_home properties
gradle.properties
org.gradle.java.home=C:\Program Files (x86)\Java\jdk1.8.0_121
I had also changed the eclipse.ini file by adding the following lines.
-vm
C:\Program Files (x86)\Java\jdk1.8.0_121\bin\javaw.exe
Still I find that the gradle build is failing.
What am I doing wrong?

Related

InteliJ -- Gradle 'test' project refresh failed Error:Error:Could not create parent directory for lock file

I am new to Gradle, I am using InteliJ, just start a new project using using Gradle, when I try to refresh my build.gradle, it says
Gradle 'test' project refresh failed
Error:Error:Could not create parent directory for lock file C:\Program Files\gradle-2.7\wrapper\dists\gradle-3.5-rc-2-bin\ktl4k9rdug30mawecgppf5ms\gradle-3.5-rc-2-bin.zip.lck
Any ideas how to fix this?
this is my build.gradle
group 'com.maxinrui'
version '1.0-SNAPSHOT'
buildscript{
repositories{
mavenCentral()
}
dependencies{
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE'
}
}
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.2.6.RELEASE'
}
I think issue with your classpath, check your build path. if not set then you need to set. You can set classpath 'com.android.tools.build:gradle:2.3.0'
and add distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip into gradle-wrapper.properties file.
Then sync your project.

org.gradle.initialization.DefaultSettings_Decorated cannot be cast to org.gradle.api.internal.project.ProjectInternal

I tried to create spring boot application:
I selected components I need from https://start.spring.io/
Now I want to build the application and it fall downs:
FAILURE: Build failed with an exception.
* Where:
Settings file 'D:\objectsharingsystem\settings.gradle' line: 2
* What went wrong:
A problem occurred evaluating settings 'object-sharing-system'.
> Failed to apply plugin [id 'org.gradle.java']
> org.gradle.initialization.DefaultSettings_Decorated cannot be cast to org.gradle.api.internal.project.ProjectInternal
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
settings.gradle:
rootProject.name = 'object-sharing-system'
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
build.gradle:
buildscript {
ext {
springBootVersion = '2.0.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: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.microsoft.sqlserver:mssql-jdbc')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Please help to find mistake.
settings.gradle can not handle application of Project level plugin.
Remove apply plugin and compileJava from settings.gradle.
You already have your sourceCompatibility set in build.gradle
See here where it says
method calls within the settings file is delegated to a settings object. Look at the Settings class in the API documentation for more information.
Unlike build.gradle, the apply method in settings.gradle expects a Plugin<Settings> and not a Plugin<Project>. The java plugin is a Plugin<Project> and can't be applied like this in settings.gradle

Eclipse error during resolving gradle dependency

I have added the dependency com.sun.mail:javax.mail:1.5.4 to build.gradle, but Eclipse doesn't resolve this dependency and throws this error
Illegal entry in Gradle Dependencies: D:/Programs/Eclipse/unresolved dependency - com.sun.mail javax.mail 1.5.4 PluginName Unknown org.springsource.ide.eclipse.gradle.core.classpathcontainer
I tried to clean & rebuild the project, refresh dependencies many times, but I still get the same error and the dependency doesn't download. What can be wrong?
My build.gradle file:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'PluginName',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
maven {
name 'Sponge maven repo'
url 'http://repo.spongepowered.org/maven'
}
}
dependencies {
compile 'org.spongepowered:spongeapi:2.1-SNAPSHOT'
compile 'com.sun.mail:javax.mail:1.5.4'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
I definietly don't know why, but It started to work and dependency just downloaded.

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: migrate spring app to a multiproject build

I followed this tutorial. This runs fine.
I would like to create a multiproject build with one project that contains this spring application. So I added this project to a subfolder called web of this multiproject build, added a settings.gradle file:
include 'web'
As well as a build.gradle file:
apply plugin: 'application'
mainClassName = "hello.Application"
jar {
baseName = 'VoPro'
}
dependencies {
compile project(':web')
}
However, when i run $ gradle build, i get the error:
Could not resolve all dependencies for configuration ':runtime'.
> Cannot resolve external dependency org.springframework.boot:spring-boot-starter-web: because no repositories are defined.
Required by:
:test:unspecified > test:web:unspecified
Why can't gradle find any repositories?
EDIT: The web subproject contains the following build.gradle file (like in the tutorial):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.2.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()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
You should add a build.gradle file under the web project itself and configure appropriate repositories there. Or add a global build.gradle and the following piece of code in it:
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
Basically the multimodule project should have the following structure
-- build.gradle // all projects configuration
-- settings.gradle //includes all modules
-- module1
-- build.gradle
-- module2
-- build.gradle
-- modulen
-- build.gradle
..
After discussion in comments:
You need to specify the dependency along with version, no idea why:
compile("org.springframework.boot:spring-boot-starter-web:1.2.2.RELEASE")

Categories