Jan Vladimir Mostert
Jan Vladimir Mostert

Reputation: 12972

publishing to mavenLocal using build.gradle.kts

I'm trying to publish an artifact to ~/.m2 (maven-local) and as a Gradle newbie, i'm not sure what i'm missing

All the examples i've seen so far suggests using a publishing block which throws deprecation warnings when i run any Gradle commands. Also including the maven-publish plugin without any publishing block causes the same warnings.

repositories {
    mavenLocal()
    jcenter()
}

plugins {
    `maven-publish`
    kotlin("jvm") version("1.3.10")
    id("org.jetbrains.dokka") version "0.9.16"
}

As part of making the publishing plugins stable, the 'deferred configurable' behavior of the 'publishing {}' block has been deprecated. In Gradle 5.0 the 'enableFeaturePreview('STABLE_PUBLISHING')' flag will be removed and the new behavior will become the default. Please add 'enableFeaturePreview('STABLE_PUBLISHING')' to your settings file and do a test run by publishing to a local repository. If all artifacts are published as expected, there is nothing else to do. If the published artifacts change unexpectedly, please see the migration guide for more details: https://docs.gradle.org/4.10.2/userguide/publishing_maven.html#publishing_maven:deferred_configuration.

If it actually published to maven-local, i might have ignored the warning for now, but it's not publishing at all, neither does gradle publishToMavenLocal, it simply says BUILD SUCCESSFUL in __s with the above warning.

Trying the recommended route (according to the link) of adding the publishing block inside a subprojects block causes lots of red in intellij

enter image description here

Not sure if that's Kotlin DSL or not ... trying something else that was shown on the Kotlin DSL version of the Gradle Docs:

enter image description here

enter image description here

Any idea what i'm missing?

Here's my Gradle version and other relevant info (IntelliJ has Kotlin 3.1.0)

gradle -version

------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------

Build time:   2018-09-19 18:10:15 UTC
Revision:     b4d8d5d170bb4ba516e88d7fe5647e2323d791dd

Kotlin DSL:   1.0-rc-6
Kotlin:       1.2.61
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_151 (Oracle Corporation 25.151-b12)
OS:           Mac OS X 10.14.1 x86_64

Upvotes: 6

Views: 6985

Answers (1)

Yoni Gibbs
Yoni Gibbs

Reputation: 7018

I think all you need to do is apply the maven plugin then run the install task. Details of how to apply the plugin are here, e.g. using the Kotlin DSL you'd have:

plugins {
    maven
}

Then you just run the install task, e.g. from your IDE (the Gradle window in IntelliJ in your case) or a command line, e.g. ./gradlew install.

Regarding applying the maven plugin, if you're new to Gradle you probably want to get clear on the Gradle plugins DSL (which the above code snippet is an example of). If you're not using that then the way you apply the plugin is slightly different (e.g. you have to use the apply command). There are details here. Note that the decision about whether to use the Gradle plugins DSL is different from the choice of using Groovy or Kotlin for the language in which you write the build.gradle file.

Upvotes: 4

Related Questions