Plugin with id 'com.github.spotbugs' not found - gradle

I'm configuring SpotBugs plugin for a Gradle project for the first time.
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
}
}
apply plugin: 'com.github.spotbugs'
When running gradle check I'm getting error Plugin with id 'com.github.spotbugs' not found. What am I doing wrong?
Gradle version 5.0.

Related

why doesn't the gradle repository definition work?

I'm at a loss why gradle is ignoring the 'repository' section of a pretty simple build.gradle file. We're behind a firewall, using a JFrog repository to use our own scanned versions of things, not Maven central. When I run 'gradle compile', I get:
FAILURE: Build failed with an exception.
Where:
Build file '/Users/exampleuser/src/example/tlp-platform-portal/build.gradle' line: 2
What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.6.3'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.6.3')
Searched in the following repositories:
Gradle Central Plugin Repository
But my build.gradle has no mention of Gradle central; the file looks like the attached.
--------build.gradle---------------------
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
maven {
url 'https://example.jfrog.io/artifactory/penalty-maven-local'
credentials {
username = System.getenv('ARTIFACT_USERNAME')
password = System.getenv('ARTIFACT_PASSWORD')
}
}
maven {
url 'https://example.jfrog.io/artifactory/dha-gradle-plugin-remote-cache'
credentials {
username = System.getenv('ARTIFACT_USERNAME')
password = System.getenv('ARTIFACT_PASSWORD')
}
}
maven {
url 'https://example.jfrog.io/artifactory/plugins-release'
credentials {
username =System.getenv('ARTIFACT_USERNAME')
password =System.getenv('ARTIFACT_PASSWORD')
}
}
maven {
url "https://example.jfrog.io/example/libs-snapshot"
credentials {
username = System.getenv('ARTIFACT_USERNAME')
password = System.getenv('ARTIFACT_PASSWORD')
}
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
(lots more)
Repositories for plugins resolution must be configured in the settings.gradle file, see detailed explanation why to use custom/private repositories here : https://docs.gradle.org/current/userguide/plugins.html#sec:custom_plugin_repositories

Gradle plugin that loads org.springframework.boot into projects

I'm writing a custom gradle plugin Foo and I want to load the org.springframework.boot plugin
into projects that apply the Foo plugin. I can load various other plugins this way, but this
particular plugin doesn't want to behave the same way.
Foo build.gradle
buildscript {
ext {
springBootVersion = "2.1.3.RELEASE"
}
}
apply plugin: "groovy"
repositories {
maven { url "http://custom.repo/blah" }
}
dependencies {
implementation gradleApi()
implementation localGroovy()
implementation("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
Foo plugin
class BuildPlugin implements Plugin<Project> {
#Override
void apply(Project project) {
project.repositories {
maven { url "http://custom.repo/blah" }
}
project.plugins.apply("org.springframework.boot")
}
}
Project build.gradle
buildscript {
dependencies {
classpath files("/some/cool/path/foo-plugin.jar")
}
}
apply plugin: "com.whatever.foo-id"
Project build output
$ ./gradlew --stacktrace clean build
FAILURE: Build failed with an exception.
* Where:
Build file '/cool/project/location/bar/build.gradle' line: 40
* What went wrong:
A problem occurred evaluating root project 'bar'.
> Failed to apply plugin [id 'com.whatever.foo-id']
> Plugin with id 'org.springframework.boot' not found.
Is it possible to apply a plugin 1 from plugin 2 where plugin 1 is a classpath dependency?
This isn't possible. The classpath is what pulls in the plugins, so it is impossible for them to modify the thing before they are pulled in.

Could not find method bootJar() for arguments

While building the gradle project I am getting below error-
FAILURE: Build failed with an exception.
Where:
Build file '/Users/vdubey/Documents/microservices/workspace/Promo-Service/build.gradle' line: 30
What went wrong:
A problem occurred evaluating root project 'Promo-Service'.
Could not find method bootJar() for arguments [build_3jq74tz48uic808y18txabjvx$_run_closure1#5c4aa147] on root project 'Promo-Service' of type org.gradle.api.Project.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
Any clue why it is failing?
I had this error while following the Spring Boot with Docker guide because my application is using Spring Boot 1.5.10.RELEASE and bootRun was only introduced in 2.0.0.
Luckily, the Spring Boot Docker guide code is in a Github repository, so I was able to navigate back to a pre 2.0.0 version: https://github.com/spring-guides/gs-spring-boot-docker/tree/8933f6efa9a94cf596095658dc0b81986d11a3ec
See the completed build.gradle file for 1.5.10-RELEASE:
// This is used as the docker image prefix (org)
group = 'springio'
jar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
// tag::task[]
docker {
name "${project.group}/${jar.baseName}"
files jar.archivePath
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
// end::task[]
Consider checking the presence of gradle plugin for Spring Boot:
https://plugins.gradle.org/plugin/org.springframework.boot
For Gradle 2.1 and later:
plugins {
id "org.springframework.boot" version "2.1.0.RELEASE"
}
For older Gradle versions:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.0.RELEASE"
}
}
apply plugin: "org.springframework.boot"
I had this problem when I am following official Spring testing-web guide. They offer initial gradle file as below.
buildscript {
repositories { mavenCentral() }
}
plugins { id "io.spring.dependency-management" version "1.0.4.RELEASE" }
ext { springBootVersion = '2.0.5.RELEASE' }
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
bootJar {
baseName = 'gs-testing-web'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
}
But when I run the ./gradlew clean command I get the below exception
Could not find method bootJar() for arguments [] on root project '' of type org.gradle.api.Project.
The problem is instead of using plugins { id "io.spring.dependency-management" version "1.0.4.RELEASE" } use id "org.springframework.boot" version "2.1.3.RELEASE". Also don't forget the java and io.spring.dependency-management plugins.
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
8.1. Reacting to the Java plugin
When Gradle’s java plugin is applied to a project, the Spring Boot plugin:
Creates a BootJar task named bootJar that will create an executable,
fat jar for the project. The jar will contain everything on the
runtime classpath of the main source set; classes are packaged in
BOOT-INF/classes and jars are packaged in BOOT-INF/lib
8.4. Reacting to the dependency management plugin
When the io.spring.dependency-management plugin is applied to a
project, the Spring Boot plugin will automatically import the
spring-boot-dependencies bom.
I shared valid build.gradle file below which can be a starting point for anyone who have this problem.
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.6/userguide/tutorial_java_projects.html
*/
plugins {
id "org.springframework.boot" version "2.1.3.RELEASE"
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
ext {
springBootVersion = '2.1.3.RELEASE'
}
// In this section you declare where to find the dependencies of your project
repositories {
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
}
bootJar {
mainClassName = 'com.softwarelabs.App'
baseName = 'spring-boot-integration-test'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// This dependency is found on compile classpath of this component and consumers.
compile 'com.google.guava:guava:23.0'
testCompile("org.springframework.boot:spring-boot-starter-test")
// Use JUnit test framework
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
}
For more details please check the spring boot gradle plugin documentation getting started part.
Check how the Spring Boot plugin reacts by other plugins.
I had this error while building a repository I had downloaded.
I was able to resolve the same by modifying my build.gradle to include a buildscript dependency for spring-boot-gradle-plugin and apply org.springframework.boot as a plugin
buildscript {
ext {
springBootVersion = '<Spring boot version>'
}
repositories {
...<my repository config>...
}
// These are gradle build dependencies and not application requirements
dependencies {
...<other dependencies>...
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
apply plugin: 'org.springframework.boot'

gradle error Could not find method dependencyManagement()

Below is my build.gradle
buildscript {
ext {
springBootVersion = '2.0.0.M3'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'maven-publish'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR7'
}
}
dependencies {
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compile "org.elasticsearch:elasticsearch:5.5.0"
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I was using gradle 2.14 and got the below error
> Failed to apply plugin [id 'org.springframework.boot']
> Spring Boot plugin requires Gradle 3.4 or later. The current version is Gra
dle 2.14
Then I upgraded gradle to 3.4 as suggested in the error message.
Now I get the below error
Could not find method dependencyManagement() for arguments [build_79bcact4bkf1
sckkod1j3zl7l$_run_closure1#4a2d71c9] on root project 'myproject'
of type org.gradle.api.Project.
Is the method dependencyManagement() no longer available in gradle 3.4 ?
If anybody is aware of the alternate method to be used in gradle 3.4 , kindly revert
To use this DSL you have to provide the dependency-management-plugin:
buildscript {
repositories {
maven {
jcenter() //or mavenCentral()
}
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: "io.spring.dependency-management"
Or you can use:
plugins {
id "io.spring.dependency-management" version "1.0.3.RELEASE"
}
More details here.
For me the fix was replacing the distributionUrl in the gradle-wrapper.properties with:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
and updating the dependencies in the build.gradle file to:
dependencies { classpath "com.android.tools.build:gradle:7.0.4" }
In Gradle 7 this error is also caused by importing a BOM using:
dependencyManagement {
imports {
mavenBom "tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}"
}
}
In Gradle 7 you need to import your BOM in the following way:
implementation platform("tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}")

build.gradle - error deploying artifact

I'm having issues with publishing to local nexus maven repository.
I admit, I don't have much experience with using gradle.
I will say that I have tried understanding the documentation and examples that are given through the gradle website (along with a few stackoverflow questions).
I am getting the following error when I try to publish:
Execution failed for task ':publishMavenPublicationToMavenRepository'.
> Failed to publish publication 'maven' to repository 'maven'
> Error deploying artifact 'com.myproject:myproject-sdk:jar': Error deploying artifact: Resource to deploy not found: File: http://git.site.com:8081/nexus/content/repositories/releases/com/myproject/myproject-sdk/3.0.0/myproject-sdk-3.0.0.jar does not exist
the entire build.gradle file looks like this:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'build-version'
buildscript {
repositories {
maven { url "http://git.site.com:8081/nexus/content/groups/public" }
maven { url 'https://geonet.artifactoryonline.com/geonet/public-releases' }
mavenCentral()
}
dependencies {
classpath 'nz.org.geonet:gradle-build-version-plugin:1.+'
}
}
repositories {
maven {
url "http://git.site.com:8081/nexus/content/groups/public"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.code.gson:gson:2.2.4'
compile 'commons-codec:commons-codec:1.9'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
publishing {
publications {
maven(MavenPublication) {
artifactId = 'myproject-sdk'
groupId = 'com.myproject'
version '3.0.0'
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
repositories {
maven {
// nexus maven credentials
credentials {
username "MY_USERNAME"
password ""MY_PASSWORD"
}
if(version.endsWith('-SNAPSHOT')) {
url "http://git.site.com:8081/nexus/content/repositories/snapshots"
} else {
url "http://git.site.com:8081/nexus/content/repositories/releases"
}
}
}
}
I am using Android Studio and this project is a Java project.
I don't understand the message because it says "Resource to deploy not found" and it points to a url at nexus.
I would expect a message like "Resource to deploy not found: File: c:/directory_that_doesn't_exist/whatever.jar"
Additional Information -
The gradle tasks listed under 'All tasks' are:
assemble
build
buildDependents
buildNeeded
check
classes
clean
compileJava
compileTestJava
generatePomFileForMavenPublication
jar
javadoc
processResources
processTestResources
publish
publishMavenPublicationToMavenLocal
publishMavenPublicationToMavenRepository
publishToMavenLocal
sourceJar
test
testClasses

Resources