hello i needed some help with publishing gradle pl...
# community-support
s
hello i needed some help with publishing gradle plugin i am writing gradle plugin for kotlin foundation gsoc i had issues publishing it can anyone help me with it
c
• Avoid posting the same question on multiple channels. One channel is enough, and if needed to repost to another channel, post the link to avoid duplication.
https://community.gradle.org/contributing/community-slack/#asking-questions-on-slack
p
Just show your error message and the minified build script
s
https://github.com/Suhas-Koheda/GSOCPlugin Thanks a lot for responding man! This is my plugin code When i publish it gets published I am on ubuntu When i ls the repository i find my project but it has only pom file When it try to import in another project i get error I cant show that now i don't have my pc wid me ryt now If any silly errors please ... I'm a newbie to gradle and plugins
c
v
Actually the opposite. You should remove your whole
publishing
block as it is pointless.
mavenLocal()
(which you should avoid to ever use whenever possible) is always available for publishing and never needs to be declared explicitly for publishing
til 1
And the
java-gradle-plugin
already registers the publications you need for your plugin for you, one for the code artifact and one for the marker artifact of each plugin.
So applying the
java-gradle-plugin
and
maven-publish
plugin is sufficient and your whole
publishing
block should go away.
s
Plugin - Build.gardle.kts:
Copy code
plugins {
    kotlin("jvm") version "1.9.24"
    `java-gradle-plugin`
    `maven-publish`
}

group = "dev.haas"
version = "1.0.0"

repositories {
    mavenCentral()
    gradlePluginPortal()
}

dependencies {
    implementation(kotlin("stdlib"))
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
}

kotlin {
    jvmToolchain(17)
}

gradlePlugin {
    plugins {
        create("kotlinPlugin") {
            id = "dev.haas.kotlinplugin"
            implementationClass = "dev.haas.SourceInspectionPlugin"
        }
    }
}
Test- Build.gradle.kts:
Copy code
plugins {
    id("dev.haas.kotlinplugin") version "1.0.0"
}

group = "dev.haas"
version = "1.0-SNAPSHOT"

repositories {
    gradlePluginPortal()
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.10.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}
Outputs: when i run publishtomavenlocal
Task :generateMetadataFileForPluginMavenPublication
Caching disabled for task ':generateMetadataFileForPluginMavenPublication' because: Build cache is disabled Not made cacheable, yet Task ':generateMetadataFileForPluginMavenPublication' is not up-to-date because: Task.upToDateWhen is false. Resolve mutations for :generatePomFileForPluginMavenPublication (Thread[Execution worker,5,main]) started. :generatePomFileForPluginMavenPublication (Thread[Execution worker,5,main]) started.
Task :generatePomFileForPluginMavenPublication
Caching disabled for task ':generatePomFileForPluginMavenPublication' because: Build cache is disabled Task ':generatePomFileForPluginMavenPublication' is not up-to-date because: Task is untracked because: Gradle doesn't understand the data structures used to configure this task Resolve mutations for :publishPluginMavenPublicationToMavenLocal (Thread[Execution worker,5,main]) started. :publishPluginMavenPublicationToMavenLocal (Thread[Execution worker,5,main]) started.
Task :publishPluginMavenPublicationToMavenLocal
Caching disabled for task ':publishPluginMavenPublicationToMavenLocal' because: Build cache is disabled Task ':publishPluginMavenPublicationToMavenLocal' is not up-to-date because: Task has not declared any outputs despite executing actions. Publishing to maven local repository Resolve mutations for :publishToMavenLocal (Thread[Execution worker,5,main]) started. :publishToMavenLocal (Thread[Execution worker,5,main]) started.
Task :publishToMavenLocal
Skipping task ':publishToMavenLocal' as it has no actions. BUILD SUCCESSFUL in 735ms 10 actionable tasks: 6 executed, 4 up-to-date
~/Kotlin/untitled3 git:[main] ls ~/.m2/repository/dev/haas///kotlinplugin//dev.haas.kotlinplugin.gradle.plugin/1.0.0/ dev.haas.kotlinplugin.gradle.plugin-1.0.0.pom the contents of my plugin
I am using only maven publishing I have updated my build scirpt
Copy code
plugins {
    kotlin("jvm") version "1.9.24"
    `java-gradle-plugin`
    `maven-publish`
}

group = "dev.haas"
version = "1.0.0"

repositories {
    mavenCentral()
    gradlePluginPortal()
}

dependencies {
    implementation(kotlin("stdlib"))
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
}

kotlin {
    jvmToolchain(17)
}

publishing {
    publications {
        create<MavenPublication>("maven") {
            groupId = "dev.haas"
            artifactId = "kotlingradleplugin"
            version = "2.0"

            from(components["java"])
        }
    }
}
with this when i publish i get two plugins created: ~/Kotlin/untitled3 git:[main] ls ~/.m2/repository/dev/haas/ kotlingradleplugin untitled3 but when i try to use it none of them work
Copy code
plugins {
    id("dev.haas.kotlingradleplugin") version "2.0"
} 
or
plugins {
    id("dev.haas.untitled3") version "1.0.0"
}
v
The error message is quite clear, isn't it?
s
sorry i dont understand
v
Searched in the following repositories:
Gradle Central Plugin Repository
You do not have Maven local as plugin repository
s
i am very much new to plugins
Copy code
plugins {
    id("dev.haas.untitled3") version "1.0.0"
}

group = "dev.haas"
version = "1.0-SNAPSHOT"

repositories {
    mavenLocal()
    gradlePluginPortal()
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.10.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}
my test project build file
v
So?
s
it has mavenlocal() configured in repositories right
can you please clone my plugin code publish it on your machine and check if it is working https://github.com/Suhas-Koheda/GSOCPlugin
v
No, it has maven local for dependencies, not for plugins
plugin repositories are declared in your settings script in the plugin management block
you see in the error message the list of repositories that was searched in
and that is only the plugin portal which is the sole default if you don't configure anything explicitly
s
ohh now i undertsand
how do i configure repository for plugins?
v
I just told you
s
it is searching for dev.haas.kotlingradleplugindev.haas.kotlingradleplugin.gradle.plugin2.0 while i have dev.haas.kotlingradleplugin:2.0
v
In your repo you still have a publishing block, but you should have none. And you published version 1.0.0 but try to consume 2.0
s
okay ive updated it
Copy code
plugins {
    kotlin("jvm") version "1.9.24"
    `java-gradle-plugin`
    `maven-publish`
}

group = "dev.haas"
version = "1.0.0"

repositories {
    mavenCentral()
    gradlePluginPortal()
}

dependencies {
    implementation(kotlin("stdlib"))
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
}

kotlin {
    jvmToolchain(17)
}
my project name is untitled3 so i should refernece with dev.haas.untitled3 with version1.0.0
Copy code
id("dev.haas.untitled3") version "1.0.0"
Copy code
pluginManagement {
    repositories {
        mavenCentral()
        mavenLocal()
    }
}
added this to settings gradle still doesnt work Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Included Builds (No included builds contain this plugin) - Plugin Repositories (could not resolve plugin artifact 'dev.haas.untitled3dev.haas.untitled3.gradle.plugin1.0.0') Searched in the following repositories: MavenRepo MavenLocal(file:/home/suhas-koheda/.m2/repository/) at org.gradle.plugin.use.resolve.internal.PluginResolutionResult.getFound(PluginResolutionResult.java:112) at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolvePluginRequest(DefaultPluginRequestApplicator.java:192) at org.gradle.
l
I added to your settings file:
Copy code
pluginManagement {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
}
and commented out the publishing block in your build file. And it worked fine when i published to maven local:
v
I said you should remove the
publishing
block. But you also now removed the
gradlePlugin
block. Without that, you do not have any plugin defined, so no marker artifact is published and hence no plugin to consume.