Our project currently applies a single plugin, the
Application Plugin
which is bundled with Gradle:
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
}
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
Let’s apply a plugin to our project that is maintained and distributed by Gradle called the
Maven Publish Plugin
.
The Maven Publish Plugin provides the ability to publish build artifacts to an
Apache Maven repository
.
It can also publish to Maven local which is a repository located on your machine.
The default location for Maven local repository may vary but is typically:
-
Mac
: /Users/\[username]/.m2
-
Linux
: /home/\[username]/.m2
-
Windows
: C:\Users\[username]\.m2
A publication destined for a Maven repository normally includes:
Apply the plugin by adding
maven-publish
to the plugins block in
build.gradle(.kts)
:
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
id("maven-publish")
}
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'maven-publish'
}
Don’t forget to sync Gradle if you are using IntelliJ IDEA.
Let’s make sure the plugin has been applied by looking at the new tasks that are available.
Run
./gradlew :app:tasks
in your command line:
$ ./gradlew :app:tasks
> Task :app:tasks
------------------------------------------------------------
Tasks runnable from project ':app'
------------------------------------------------------------
...
Publishing tasks
----------------
publish - Publishes all publications produced by this project.
publishToMavenLocal - Publishes all Maven publications produced by this project to the local Maven cache.
A new set of publishing tasks are now available called
publish
, and
publishToMavenLocal
.
Similarly, the new tasks from the Maven Publish plugin are now available in IntelliJ in the Gradle right-hand pane.