Gradle dependency management plugin - gradle

I am trying to run the following minimal gradle build file including the dependency management plugin:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
But then running gradle fails:
* What went wrong:
Plugin [id: 'io.spring.dependency-management', version: '1.0.4.RELEASE'] 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 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.4.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warnings
Is there a missing dependency in the gradle file?

The plugin cannot be found because you defined repositories inside your build script and tried to use plugin outside it. Remove buildscript or add repositories for your build file also.
(Dependencies and repositories defined inside build script are accessible in that buildscript scope)
Example:
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}

Related

avro gradle plugin failing to build using gradle

I am trying to build the avro gradle plugin using gradle and even though I had set my settings.gradle as :
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
and build.gradle :
plugins {
id "com.github.davidmc24.gradle.plugin.avro" version "1.3.0"
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.apache.avro:avro:1.11.0"
}
generateAvroJava {
source("${projectDir}/src/main/resources/avro")//sourcepath avrofile
}
while executing the gradle build I get the errors below:
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.github.davidmc24.gradle.plugin.avro', version: '1.11.0'] 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 'com.github.
not sure if I am missing something that is causing it to fail. any ideas.. thanks.

Gradle: Invalid publication 'maven': artifact file does not exist

Java 11 and Gradle 7.2 here. I am trying to build a reusable library that I can (eventually) publish to a Maven repository and pull into other projects. But first I just want to get it publishing to my local m2 repo.
The project directory structure looks like:
mylib/
lib/
src/
build.gradle
Where build.gradle is:
plugins {
id 'java-library'
id 'maven-publish'
id 'io.freefair.lombok' version "6.5.0-rc1"
}
sourceCompatibility = 1.11
targetCompatibility = 1.11
archivesBaseName = 'mylib'
version = '1.0.0-RC1'
group = 'org.example'
repositories {
mavenCentral()
}
dependencies {
// omitted for brevity
)
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
}
publishing {
publications {
maven(MavenPublication) {
artifact("build/libs/${archivesBaseName}-${version}.jar") {
extension 'jar'
}
}
}
}
tasks.named('test') {
useJUnitPlatform()
}
publishToMavenLocal.configure {
mustRunAfter build
}
When I run gradle publishToMavenLocal I get:
% ./gradlew clean build publishToMavenLocal
> Task :lib:publishMavenPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'mavenLocal'
> Invalid publication 'maven': artifact file does not exist: '/Users/myuser/workspace/mylib/lib/build/libs/mylib-1.0.0-RC1.jar'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 833ms
6 actionable tasks: 6 executed
So it looks like even though I'm specifying (on the command line) to run clean then build then publishToMavenLocal, and even though I'm even specifying (in build.gradle) that publishToMavenLocal must run after build, it seems what is happening is:
publishToMavenLocal insists on running first (before clean or build)
Since the JAR hasn't been built yet, no JAR file exists at the location specified ("build/libs/${archivesBaseName}-${version}.jar")
The build fails because the artifact doesn't exist
So I think I just need to get build to run before publishToMavenLocal but I'm out of ideas.
You're mixing the plugins DSL (plugins { }) with legacy plugin application (apply plugin). That's not a big deal, but you should go with #sean's answer and use the plugins DSL instead which will solve your issue.
To your problem at hand
Could not get unknown property 'plugin'
That happens because you missed the : in apply plugin
apply plugin: 'maven-publish'
Try placing your plugins in this way. Not sure if that resolves your issue though.
plugins {
id 'java-library'
id 'maven-publish'
}

Gradle doesn't find plugins: org.jetbrains.kotlin.jvm and kotlin2js

I'm a beginner in gradle, using version 4.8.
Whatever I do , the plugins are never found. I get this error message:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.3.20'] 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.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.3.20')
Searched in the following repositories:
Gradle Central Plugin Repository
No matter how many repositories I add, it seems it is only looking in "Gradle Central Plugin Repository"
My gradle.build file:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
classpath "org.jetbrains.kotlin.jvm:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.20'
id 'kotlin2js' version '1.3.20'
}
Can you help me?
Try the following gradle.build configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
id 'java'
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
When you include the plugin by id, it seems Gradle wants to retrieve the plugin from the Gradle plugin portal, but the Kotlin plugin is not there, it's part of the buildscript dependency. Using it with the apply plugin works. You can also find a slightly different working example here.
I had similar problem because i forgot about proxy settings like systemProp.https.proxyHost and systemProp.http.proxyHost and etc. that was set in ~/.gradle/gradle.properties.
I fixed configuration and plugin was successfully dowlnloaded
Check gradle.properties and try to add correct proxy settings if you behind firewall or escape this settings if you not.
you need to add repository mavenCentral() to the buildscript dependencies.
for example: kotlin-gradle-plugin:1.3.20. also the documentation hints for that.
Go to your project and then to the Gradle script. In Gradle, Go to Setting.Gradle and change the Fist Bitray Url to https://plugins.gradle.org/m2/.

gradle build for kotlin code

I'm trying to set up a project building Kotlin code with Gradle. I've followed instructions here on how to set up the build.gradle file but am receiving an error
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0'
}
}
apply plugin: 'kotlin'
With this I get the error:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'kjsonparser'.
Could not resolve all files for configuration ':classpath'.
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0.
Required by:
project :
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0.
Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0/kotlin-gradle-plugin-1.2.0.pom'.
Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0/kotlin-gradle-plugin-1.2.0.pom'.
java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
I've also tried the "newer" way of specifing the plugin
plugins {
id "org.jetbrains.kotlin.jvm" version "1.2.0"
}
Which gives this error:
What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.0'] 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.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.2.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Version of Gradle
gradle -version
------------------------------------------------------------
Gradle 4.4
Kotlin (and openjdk)
kotlin -version
Kotlin version 1.2.0 (JRE 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)
Running on Ubuntu 17.10
I've never worked with Gradle before so not sure if I'm missing anything in the build file
Try this. It works:
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
I never use the buildscript block.
Try this instead:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.4.31'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.31'
}

Gradle fails to resolve spring dependency

I am trying to build my project with the following build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
repositories {
maven {
url 'https://repo.spring.io/milestone'
}
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-mongodb:1.2.2.RELEASE')
compile('org.springframework.data:spring-data-mongodb:1.7.0.RC1')
compile('org.springframework.cloud:spring-cloud-spring-service-connector')
compile('org.springframework.cloud:spring-cloud-cloudfoundry-connector')
compile 'org.springframework:spring-test:4.1.5.RELEASE'
compile 'de.grundid.opendatalab:geojson-jackson:1.3'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.1'
compile 'org.apache.httpcomponents:httpclient:4.4'
testCompile('junit:junit')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
I added the milestone repository because I need the spring-data-mongodb 1.7.0.RC1 dependency. However, there seems to be something wrong with the references of the parent-poms because gradle is unable to fetch the following dependency: org.springframework.data.build:spring-data-parent:1.6.0.RC1
It exits with the following error:
Could not find org.springframework.data.build:spring-data-parent:1.6.0.RC1.
Searched in the following locations:
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
The output of the gradlew build --debug command can be found here: http://pastebin.com/seYRMFQP
The command additionally produced the following output to stdout: http://pastebin.com/atcWQsKF
I already tried to clean my local gradle cache but it did not resolve the problem.
Sorry for the inconvenience, the artifact is currently misplaced in the release repository, though it should be in milestone.
We'll move it to milestone asap. Until that happens please add the release repository url 'https://repo.spring.io/release' to your build.
seems the repositories you defined in your build do not contain the libraries you're looking for. but it seems the lib is available in jcenter. to add jcenter add the following snippet to your build.gradle file:
repositories {
jcenter()
}
cheers,
René

Resources