Gradle installing/using a plugin jar locally

Viewed 749

In my project I have a proprietary jar that has to be accessed locally. I have tried to find out different ways to install the jar in local maven repository following the official guide.

https://docs.gradle.org/current/userguide/publishing_maven.html

But it is not working.

I have made a build.gradle file as follows,

plugins {
    id 'maven-publish'
}

project.afterEvaluate {
    publishing {
        publications {
            maven(MavenPublication) {
                groupId = 'com.xxx.yyy.zzz'
                artifactId = 'XYZ'
                version = 'X.X.X'

                from components.java
            }
        }
    }
}

In the project settings.gradle.kts the jar is fetched by,

plugins {
    id("com.xxx.yyy.zzz.XYZ") version "X.X.X"
}

Now, in maven I used to install jars to local repository by mentioning the jar name.

As I am new to gradle possibly I missing some vital understanding.

After executing the command gradle publishToMavenLocal I am getting the error,

gradle publishToMavenLocal

FAILURE: Build failed with an exception.

* Where:
Build file '/home/xxx/yyy/zzz/build.gradle' line: 13

* What went wrong:
A problem occurred configuring root project 'zzz'.
> Exception thrown while executing model rule: PublishingPlugin.Rules#publishing(ExtensionContainer)
   > Could not get unknown property 'java' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

* 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 0s

If I remove the line from components.java the build becomes successful but the jar location is not found and when I execute main project build it says,

* What went wrong:
Plugin [id: 'com.xxx.yyy.zzz.XYZ', version: 'X.Y.Z'] 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.xxx.yyy.zzz.XYZ:X.Y.Z')
  Searched in the following repositories:
    MavenLocal(file:/home/xxx/.m2/repository)
    MavenRepo

UPDATE

The original settings.gradle.kts is,

pluginManagement {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    plugins {
    }
}
plugins {
    id("com.xxx.yyy.zzz.XYZ") version "X.Y.Z"
}

rootProject.name = "svoc-sherlock"

apply(from = "${rootProject.projectDir}/gradle/buildcache.settings.gradle.kts")

include(
    "java-platform",
    "datamodel",
    "lib-common",
    "stream-app-auto-quote-ingestion",
    "stream-app-msiclient-ingestion",
    "stream-app-msianb-quotes-ingestion"
)
1 Answers

Try this in your build.gradle:

plugins {
    id 'java'
    id 'maven-publish'
}

This simply adds the java plugin which is also needed.

Update:

In response to your comment: You need to add this line on your settings.gradle:

rootProject.buildFileName = 'build.gradle.kts' above include ':app'.

Related