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.
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"
we are facing issue while upgrading gradle 5.6 to gradle 7.2.
we have simple spring boot project(sub1) with one internal spring library project(sub 2). while sub2 is gradle spring lib which depends on sub1. Both projects are using same gradle and spring boot version.
Also we are trying to upgrade spring cloud to latest version which requires gradle upgrade and spring boot upgade. current version is shown below
gradle - 7.2
spring - 2.5.2
swagger - 2.9.2
Getting below error while I try hitting swagger url.
java.lang.IllegalArgumentException: Version must not be null o empty
Spring boot banner is blank and not showing version. we are suspecting this could be the issue.
Swagger home page shows below error:
Failed to load API definition
Gradle file:
repositories {
jcenter()
}
dependencies {
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4+'
}
}
plugins {
id "org.sonarqube" version "2.8"
id "com.gorylenko.gradle-git-properties" version "2.2.2"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: "jacoco"
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
implementation.canBeResolved = true
}
jar {
archiveVersion = "${project.findProperty('APP_VERSION') ?: 'MANUAL_BUILD'}"
dependsOn configurations.runtimeClasspath
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
(configurations.runtimeClasspath-configuration.implementation).collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
dependencies {
implementation('org.springframework:spring-webmvc:5.3.8')
implementation('org.apache.tomcat.embed:tomcat-embed-core:9.0.33')
implementation('org.aspectj:aspectjrt:1.9.5')
}
Please help us understand this issue.
there are some new features added as well as some features from gradle5X removed so, please go through the documentation once again and try to add the below dependencies that may help you in your API.
dependencies {
// Ensure you use the Groovy 3.x variant
testImplementation('org.spockframework:spock-core:2.0-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
testImplementation('org.junit.jupiter:junit-jupiter-api')
}
// Spock 2 is based on JUnit Platform and needs to be enabled explicitly.
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
also, go through this once to get more in detailed https://docs.gradle.org/current/userguide/upgrading_version_6.html
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).
I am trying to use an AspectJ Annotation that is in a Library, that I am pulling into my project. My project uses Gradle, so I am attempting to use FreeFair AspectJ Gradle Plugin.
I need to be able to set the AspectJ -aspectpath argument, to the Library Dependency that Gradle is pulling in.
FreeFair, does not seem to have much Documentation, mainly just Sample Code.
In their sample code, I see that I can use this to set the -aspectpath to a local "project":
aspect project(":aspectj:aspect")
Does anyone know how to set the -aspectpath to an external library dependency?
I created an example Project and put it on GitHub: freefair-aspectpath-external-library.
Note: I am using io.freefair.gradle:aspectj-plugin version 2.9.5 because my project is stuck using Gradle version 4.10.3.
Update: I have created a bug for this: https://github.com/freefair/gradle-plugins/issues/46
Thanks to #larsgrefer, who provided the answer in the GitHub Issue (46).
For the io.freefair.aspectj.compile-time-weaving plugin 2.9.5 the configuration is named "aspects" instead of "aspect".
The following fixed the issue:
aspects project(":aspectj:aspect")
The full build file resembles:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
// 2.9.5 for use with Gradle 4.10.3.
classpath "io.freefair.gradle:aspectj-plugin:2.9.5"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "io.freefair.aspectj.compile-time-weaving"
aspectj.version = '1.9.3'
group 'xyz.swatt'
version '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
///// SWATT ///// https://mvnrepository.com/artifact/xyz.swatt/swatt
compile group: 'xyz.swatt', name: 'swatt', version: '1.12.0'
aspect "xyz.swatt:swatt:1.12.0"
}
aspect is a plain old gradle configuration.
This means you can use all the notations described here:
https://docs.gradle.org/current/userguide/dependency_types.html#dependency_types
https://docs.gradle.org/current/userguide/declaring_dependencies.html
dependencies {
aspect project(":my-aspect")
aspect "com.example.foo:bar-aspect:1.0.0"
aspect file("foo.jar")
}
I am new to all Gradle, VAADIN and Spring, and am just working through a simple VAADIN Spring Boot tutorial (https://spring.io/guides/gs/crud-with-vaadin/) and tried to add the Canvas add-on from https://github.com/hezamu/vaadincanvas, but when I add the compile dependency
compile("org.vaadin.hezamu:canvas:2.3.0")
a VAADIN widget compile will fail with tons of weird errors:
Using Gradle Vaadin Plugin 1.3.1
:vaadinPluginVersionCheck SKIPPED
:compileJava UP-TO-DATE
:vaadinUpdateWidgetset
:processResources UP-TO-DATE
:classes UP-TO-DATE
:vaadinClassPathJar UP-TO-DATE
Errors in 'jar:file:/C:/Users/msc/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-client/8.1.8/93548adad170aea9fe62ab742908fe63fe0ec321/vaadin-client-8.1.8.jar!/com/vaadin/client/extensions/DragSourceExtensionConnector.java'
Line 413: The method getState() from the type DragSourceExtensionConnector refers to the missing type DragSourceState
Line 38: The import com.vaadin.shared.ui.dnd cannot be resolved
Line 433: DragSourceRpc cannot be resolved to a type
Line 605: DragSourceState cannot be resolved to a type
Line 39: The import com.vaadin.shared.ui.dnd cannot be resolved
Line 507: DragSourceRpc cannot be resolved to a type
Line 190: The method getState() from the type DragSourceExtensionConnector refers to the missing type DragSourceState
Line 433: The method getRpcProxy(Class<T>) in the type AbstractConnector is not applicable for the arguments (Class<DragSourceRpc>)
Line 212: DragSourceState cannot be resolved to a variable
Line 492: DropEffect cannot be resolved
Line 606: DragSourceState cannot be resolved to a type
Just by removing that one dependency, the project builds. This is the entire Gradle build file:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
classpath "com.devsoap.plugin:gradle-vaadin-plugin:1.3.1"
classpath "javax.validation:validation-api:1.1.0.Final"
}
}
plugins {
id "com.devsoap.plugin.vaadin" version "1.3.1"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.devsoap.plugin.vaadin'
jar {
baseName = 'gs-crud-with-vaadin'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/vaadin-snapshots" }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
maven { url "http://oss.sonatype.org/content/repositories/vaadin-snapshots/" }
maven { url "http://vaadin.com/nexus/content/repositories/vaadin-addons/" }
maven { url "https://plugins.gradle.org/m2/" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencyManagement {
imports {
mavenBom 'com.vaadin:vaadin-bom:8.0.0'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.vaadin:vaadin-spring-boot-starter")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.vaadin.hezamu:canvas:2.3.0")
compile("com.h2database:h2")
testCompile("junit:junit")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
What am I doing wrong? I am using Gradle 4.1 and Java 8.
There is a problem with your vaadin version. You have a bom with 8.0.0 but I guess the gradle plugin tries to use a newer version (8.1.8).
With Vaadin 8.1 the drag&drop Handling changed. I guess the addon doesn't support Vaadin 8.1 because it was released before.
You have three options.
Use some other addon if possible.
Fix the addon yourself
Or as a last resort add the following code to your build gradle to stay at Vaadin 8.0
vaadin {
version '8.0.7'
}
Well, I got it to work after "fine-tuning" all versions. VAADIN, its' addons and Gradle seem to be a fickle team. It works with the spring-boot gradle plugin 1.4.7.RELEASE (important!), VAADIN 8.1.1, the devsoap VAADIN Gradle plugin 1.3.1, the multifileupload addon 3.0.1 and the canvas addon 2.2.0.
Pretty much any change in any of these versions, and something falls apart.