I am trying to run spring-boot project. I have some problem with gradle.
gradle build works fine, but I cannot run gradlew
Cannot run command:
./gradlew build &&java -jar build/libs/gs-spring-boot-docker-0.1.0.jar
Here is error:
Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9
My gradle version 6.0
My gradle file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.cloud.tools.jib'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.postgresql:postgresql')
testCompile("org.springframework.boot:spring-boot-starter-test")
}
gradle build works fine, there is no error.
The whole point of the Gradle wrapper is to have a fixed version of Gradle used in a project. This ensures that you don't by accident use an incompatible version than what the project supports. Another benefit is that it automatically downloads the correct version if you don't have it already.
When you type gradle (without the 'w'), you are invoking a manually downloaded distribution that you put on your path. This skips the wrapper part completely. In your case, you have apparently downloaded version 6 and updated the project to work with that version.
However, you have not updated the wrapper scripts, which is what you should have done instead. If you look in gradle/wrapper/gradle-wrapper.properties, you should see that it is set to 4.9, which is no longer compatible with your project.
To update it, you need to run the following command twice:
gradlew wrapper --gradle-version 6.1.1 --distribution-type all (assuming you want version 6.1.1, which is the latest at the time of this writing.)
The first time you run it, it will basically just change the version in gradle-wrapper.properties (e.g to 6.1.1). If this fails because the wrapper is too old compared to the project, just change the file manually with a text editor.
The second time you run it, Gradle will start up using that new version (e.g. 6.1.1) and, if needed, update the wrapper scripts themselves.
Also, if you like to start your Spring Boot application during development, just run gradlew bootRun. No need to build the jar and invoke java manually.
And also, instead of compile, use implementation in your dependencies. The former is deprecated (including testCompile).
Related
I have a multiproject gradle project
project_android
project_lib
app
project-lib is in its own git repository which I added to to project_android using git subtree.
I'm stuck. In order to build project_lib by itself, I need to specify a version for this plugin. If I don't have the version
plugins {
id 'org.jetbrains.kotlin.jvm'
}
I get this error when building
* What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
```
So I add a version and then it works
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.7.10"
}
But now I can't build project_android, here is the error
Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
> Plugin request for plugin already on the classpath must not include a version
I haven't added this plugin to app so I don't know where it comes from. This is the plugins in project_android/app/build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
// Kotlin Annotation Processing Tool
id 'kotlin-kapt'
// Google Services plugin
id 'com.google.gms.google-services'
// Navigation
id 'androidx.navigation.safeargs.kotlin'
// Performance Monitoring plugin
id 'com.google.firebase.firebase-perf'
}
One project requires me to add a version. Another requires me not to add a version. What do I do to keep both happy?
Usually when I run into this it's because there is another implementation of that plug-in in one of the other gradle files. Look in your build.gradle project file and/or your gradle settings file to see if another version of 'org.jetbrains.kotlin.jvm' is listed. You may have to play around with deleting it from one of those other files and resyncing the gradle until it works.
I resolved this by using the gradle legacy plugin dsl. In project_lib\build.gradle instead of:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.17.10'
}
I instead do this
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
apply plugin: "org.jetbrains.kotlin.jvm"
I'm trying to set up an OAuth2 authorization server based a tutorial by David Steiman. Currently, I want to check if that solution still works with most current versions of the included libraries. Working solely on the OAuth2ResourceServersub-project I change the corresponding entries in build.gradle so that it now looks like this:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE')
compile('org.springframework.security:spring-security-jwt:1.0.9.RELEASE')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
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'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Actually, at first, I tried Spring Boot version 1.5.10.RELEASE which works perfectly fine. But I need to use Spring 5 and therefore Spring Boot 2. But with 2.0.0.BUILD-SNAPSHOT, the spring boot Gradle plugin tells me that I have to use at least Gradle 4.0, so I can not use the Gradle wrapper that comes with the sample project. I had version 4.2.1 installed on my system but also tried with 4.5.1. What I get when using Gradle 4 is:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\stefa\Projekte\spring-cloud-oauth2-example\OAuth2ResourceServer\build.gradle' line: 16
* What went wrong:
A problem occurred evaluating project ':OAuth2ResourceServer'.
> Failed to apply plugin [class 'io.spring.gradle.dependencymanagement.DependencyManagementPlugin']
> Could not create task of type 'DependencyManagementReportTask'.
The root cause of the corresponding stack trace is:
...
Caused by: org.gradle.internal.service.UnknownServiceException: No service of type StyledTextOutputFactory available in ProjectScopeServices.
at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:324)
at org.gradle.api.internal.DependencyInjectingInstantiator.convertParameters(DependencyInjectingInstantiator.java:110)
at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:79)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:119)
... 144 more
Which led me (among other places) there. The versions I am using should not have the problem anymore as far as I understand. But what completely confuses me is that I am actually using Spring Boot 2.0.0.BUILD-SNAPSHOT and Gradle 4.5.1 in my "real" project and it works perfectly well there.
I created an example-project which uses Spring-Boot 2 and Grade 4 and works perfectly well. What am I missing?
I have a java project that is using dagger-2 and grpc, when I try to build it using ./gradlew build I get the following error:
> java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
is MoreTypes supposed to be provided inside of dagger-2 dependencies or I should provide that dependency on the class path?
this is the relevant parts of gradle.build file content:
plugins {
id "net.ltgt.apt" version "0.10"
id "com.google.protobuf" version "0.8.1"
id "java"
}
dependencies {
compile 'io.grpc:grpc-all:1.5.0'
compile 'com.google.dagger:dagger:2.14'
apt 'com.google.dagger:dagger-compiler:2.14'
testApt 'com.google.dagger:dagger-compiler:2.14'
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
This is a problem in Dagger 2.14 fixed in 2.14.1. See issue 994, "Dagger 2.14 breaks build":
I have not isolated the issue to a small sample project at this point, but a possible cause I see is below, maybe that gives a pointer. I don't have any explicit dependency on Google Auto libs in that part of the build.
java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
Confirmed fixed in 2.14.1, which contains this commit.
When trying to build my java project using Gradle I get the following issue:
plugin with id 'sonar' not found
at the following line in my build.gradle:
apply plugin: 'sonar'
This was previously working with Gradle version 1.7 and Java 7, however I have now updated to these newer versions:
gradle : 3.4.1
Java: 1.8
What could be causing this and how could I solve it?
The sonar plugin was renamed to 'org.sonarqube'.
To use this plugin you need to add a dependency:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
}
}
And then you can apply the plugin:
apply plugin: "org.sonarqube"
Also see the plugin page.
I'm working on a Gradle project. The project downloads dependencies and runs perfectly fine when I do gradle run. Here's my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'
mainClassName = 'myProject.MyMainClass'
repositories {
mavenCentral()
}
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'org.jsoup:jsoup:1.7.2'
testCompile "junit:junit:4.11"
}
jar {
baseName = 'myproject-service'
version = '0.1.0'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
Now I want to import the project in Intellij IDEA.
Import Gradle project >> Use default gradle wrapper (recommended) >> OK
However, when I hit OK it comes up with a dialogue saying:
Could not initialize class javax.crypto.SunJCE_b
Looking in the logs, it says
org.gradle.tooling.GradleConnectionException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b
at javax.crypto.KeyGenerator.a(DashoA13*..)
...
2015-03-18 21:31:17,751 [2354198] WARN - nal.AbstractExternalSystemTask - Could not initialize class javax.crypto.SunJCE_b
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not initialize class javax.crypto.SunJCE_b
at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
...
I have no idea how to get this project to work. None of my imports from external repositories work inside IDEA without this (they all appear red). Any help would be appreciated. I'm on:
Intellij IDEA 13.1.6
Java EE 7 (jdk1.7.0_75.jdk)
Gradle 2.3
Mac OS X
SOLUTION:
Still have no idea what the issue is. I tried all the suggestions I could find online and everything I could think of: Install a different version of java, install a different IDEA, try using the original cryptography policy files, try using the unlimited strength policy files and more. None of these worked.
What did work, however, was selecting "Use a local gradle distribution", instead of using the default wrapper. I gave it my gradle install path (/usr/local/gradle-2.3), found by running which gradle (that will give you the path to the executable, namely /usr/local/gradle-2.3/bin/gradle, but I just took the directory part). Now I can build using gradle!!
My best guess is that the gradle plugin installed some other distribution of gradle that wasn't set up properly for my project.
I hope this is helpful to anyone else struggling with using gradle in Intellij IDEA.