Plugin with id 'org.ajoberstar.grgit' not found - gradle

I'm trying to compile an opensource minecraft mod called VeinMiner.
I use ./gradlew build to compile it.
However it failed and give me this reason:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/xxxx/Desktop/VeinMiner/build.gradle' line: 26
* What went wrong:
A problem occurred evaluating root project 'VeinMiner'.
> Plugin with id 'org.ajoberstar.grgit' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 14.778 secs
I have tried to git clone it again or run it in sudo.
However, neither of these two work.
This build gradle is like this:
(It's too long so I select some part of it)
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
plugins {
id 'com.matthewprenger.cursegradle' version '1.0.7'
id 'org.ajoberstar.grgit' version '1.3.2'
}
apply plugin: 'forge'
apply plugin: 'maven'
apply plugin: "org.ajoberstar.grgit"
apply plugin: "com.matthewprenger.cursegradle"
ext.git = grgit.open(file('.'))
ext {
configFile = file "build.properties"
revision = git.head().abbreviatedId
depth = git.log().size()
}
I expected to Build Successful. Have anyone met this situation?

The mentioned plugin org.ajoberstar.grgit gets applied twice. The first time it gets applied via the new plugins block, the second time via the old apply plugin: method. Simply remove the line apply plugin: "org.ajoberstar.grgit" and the error should disappear.
To apply plugins via the old apply plugin: method, the plugin package needs to be resolved from an arbitrary repository inside the buildscript block. This works in the same way as resolving project dependencies via the normal repositories and dependencies blocks.
The new plugins block directly resolves plugins from the Gradle plugin portal and applies them in the same step.
I would guess that the way how to apply to plugin was changed to the newer one, but the removal of the old method did not happen. In existing setups the plugin may have been resolved from the local Gradle cache, but on your new setup it could not be found.

Related

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 init script can't apply artifactory plugin

I'm trying to offload build logic into a gradle init script, which gets included in a custom gradle wrapper. It seems promising. One of the things I need to do is to apply the artifactory plugin prior to configuring it, while the following code works fine in build.gradle, it fails to find the plugin when the code is shifted into an init script.
build.gradle:
buildscript{
Properties properties = new Properties()
properties.load(new File(gradle.getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())
repositories {
maven {
url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
credentials {
username = properties.artifactory_user
password = properties.artifactory_password
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2"
}
}
apply plugin: "com.jfrog.artifactory"
and in the init script it's almost the same:
initscript{
Properties properties = new Properties()
properties.load(new File(getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())
repositories {
maven {
url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
credentials {
username = properties.artifactory_user
password = properties.artifactory_password
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2"
}
}
apply plugin: "com.jfrog.artifactory"
but I get Plugin with id 'com.jfrog.artifactory' not found. with this attempt.
I have also tried making an init plugin, but my plugin skills are not strong, and it also seems to fail.
I tried moving just the apply plugin line to build.gradle from the init script but that also fails, indicating it might be the dependency resolution. How can I debug this further?
I did a build scan and it appears that the plugin jar was found okay.
org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2
commons-io:commons-io:2.7
commons-lang:commons-lang:2.4
commons-logging:commons-logging:1.1.1
1.2
org.apache.ivy:ivy:2.2.0
org.jfrog.buildinfo:build-info-extractor:2.19.2
Any help, comments, suggestions appreciated.
Rant: gradle docs have far too few examples.
For gradle init script, you must use the fully qualified class name of the plugin instead of the id.
Like this:
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin

Getting gradle error "Could not get unknown property 'srcDirs' for source set 'groovy'" after upgrading to 5.5.1

I have a multi-project build and I'm including the groovy plugin in the master build.gradle like this:
plugins {
id 'groovy'
}
However, one of my subprojects which has groovy sources is doing this:
sourceSets {
main {
java.srcDirs = []
groovy.srcDirs += ["src/main/java", "src/main/groovy"]
}
}
And I get an error:
> Could not get unknown property 'srcDirs' for source set 'groovy' of type org.gradle.api.internal.tasks.DefaultSourceSet.
I'm in the process of upgrading my build scripts to work under gradle v5.5.1 rather than v2.13. This was working previously where I had this in the subproject build file:
apply plugin: 'groovy'
But after upgrading to 5.5.1 from 2.13 it started giving me this:
* What went wrong:
A problem occurred evaluating project ':mysubproj'.
> Failed to apply plugin [class 'org.gradle.api.plugins.GroovyBasePlugin']
> Cannot change attributes of configuration ':mysubproj:apiElements' after it has been resolved
Which is why I thought I should declare the plugin in the master build script.
Shouldn't my plugin reference in the master build script make the subproject aware of the groovy extensions? If not, what's the correct way? Thank you!
The issue is the Groovy plugin isn't being applied to the subproject, you will want to apply it appropriately.
allprojects {
apply plugin: 'groovy'
}
I know in the past the new plugin style didn't work for subprojects, that may have been resolved and if so - use it.
As for the exception, when you seem to be doing the above, I'd need the buildscripts to advise you :)

Use gradle to upload jar to local Maven repository

This question has been asked several times, but somehow I don't get this to work. Gradle is a great tool, but its documentation is anything but great. No examples make it almost impossible to understand for someone who doesn't use it on a daily basis.
I am using Android Studio and I want to upload my module output jar to my local Maven repository.
apply plugin: 'java'
dependencies {
compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
}
apply plugin: 'maven'
configure(install.repositories.mavenInstaller) {
pom.project {
groupId 'com.example'
artifactId 'example'
packaging 'jar'
}
}
When I start a build in Android Studio, I can see on the Gradle tab that
:install
is invoked. I also get a new jar in my build folder, but that jar is not uploaded to Maven. [The Maven repo exists and the Google appengine gradle plugin uploads its jar from another module of the same project just fine.]
What am I missing?
I suspect the problem is that you are only editing the POM (via pom.project), instead of configuring the actual Maven coordinates used for installation. Try the following instead:
// best way to set group ID
group = 'com.example'
install {
repositories.mavenInstaller {
// only necessary if artifact ID diverges from project name
// the latter defaults to project directory name and can be
// configured in settings.gradle
pom.artifactId = 'myName'
// shouldn't be needed as this is the default anyway
pom.packaging = 'jar'
}
}
PS: The samples directory in the full Gradle distribution contains many example builds, also for the maven plugin.
Peter N is CORRECT in the comments of the accepted answer, which works, but shouldn't be the accepted answer.
You should have this in your build.gradle file
apply plugin: "maven"
Then you can just do a
$ ./gradlew install
Or use the built-in task
$ ./gradlew publishToMavenLocal
Both methods install the artifacts in $HOME/.m2/com/example/example/version

How to add Project Dependency using gradle?

I am facing the following problem. I need to build the multi-project, but when I try to add the dependency I got the following error.
Root Project's settings.gradle:
include 'DbServices','HelloWeb'
Root Project's build.gradle:
apply plugin: 'java'
project(':HelloWeb') {
dependencies {
compile (':DbServices')
}
}
DbServices's build.gradle:
apply plugin: 'java'
HelloWeb's build.gradle:
apply plugin: 'java'
However, then I am getting the following error when synchronize with the gradle tasks on Root Project:
Executing command: "tasks"
FAILURE: Build failed with an exception.
Where:
Build file 'D:\MyDeployment\RootProject\build.gradle' line: 21
What went wrong:
A problem occurred evaluating root project 'RootProject'.
Could not find method compile() for arguments [:DbServices] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#3b3e3b3e.
Try:
Run with --info or --debug option to get more log output.
Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'RootProject'.
The documentation uses the following syntax:
dependencies {
compile project(':DbServices')
}
The notion of compile dependencies is introduced by the java plugin. Therefore, this plugin has to be applied (to the HelloWeb project) before declaring dependencies. The easiest way to fix this is to move the dependencies block into HelloWeb's build.gradle. Additionally, the project dependency syntax needs to be fixed according to JB Nizet's answer.

Resources