From 7a2fb8624a465a3d080d3c6f054e07ef1ea14ee0 Mon Sep 17 00:00:00 2001 From: Renato Ivancic Date: Fri, 22 Oct 2021 13:03:57 +0200 Subject: [PATCH] Local Maven Publishing (#10) * Publishing to local Maven repository --- .idea/inspectionProfiles/Project_Default.xml | 70 +++++++++++++++++++ binary-plugin/README.md | 4 +- binary-plugin/binary-plugin-example/README.md | 17 ++++- .../binary-plugin-example/build.gradle | 11 ++- .../binary-plugin-example/settings.gradle | 16 +++++ 5 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..85e0c4c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,70 @@ + + + + \ No newline at end of file diff --git a/binary-plugin/README.md b/binary-plugin/README.md index 9a3bddc..362b3fe 100644 --- a/binary-plugin/README.md +++ b/binary-plugin/README.md @@ -2,6 +2,6 @@ This directory contains assignments and examples with the focus on standalone Gradle binary plugins. -| Module | Description | Resources | +| Module | Description | Lectures | | ------------- |:-------------:|-------------:| -| **[binary-plugin-example](binary-plugin-example)** | Example showing necessary components of binary plugin, utilities that `gradle-java-plugin` plugin offers to ease up plugin binary plugin compilation and packaging. Publishing of plugin to local, private remote Maven repository or Gradle Plugin Portal is also covered. | [Binary Plugin Lecture](https://www.udemy.com/course/gradle-development/learn/lecture/28264772#overview) | \ No newline at end of file +| **[binary-plugin-example](binary-plugin-example)** | Example showing necessary components of binary plugin, utilities that `gradle-java-plugin` plugin offers to ease up plugin binary plugin compilation and packaging. Publishing of plugin to local, private/remote Maven repository or Gradle Plugin Portal is also covered. | [Binary Plugin](https://www.udemy.com/course/gradle-development/learn/lecture/28264772#overview)

[Local Maven Publish](https://www.udemy.com/course/gradle-development/learn/lecture/28264772#overview)| \ No newline at end of file diff --git a/binary-plugin/binary-plugin-example/README.md b/binary-plugin/binary-plugin-example/README.md index b350544..f95116e 100644 --- a/binary-plugin/binary-plugin-example/README.md +++ b/binary-plugin/binary-plugin-example/README.md @@ -1,7 +1,9 @@ # Binary Plugin Example This project serves as a template for Gradle binary plugin, it contains minimal content to compile it. It also contains -source code for following lecture [Gradle Plugin Development - Binary Plugin](https://www.udemy.com/course/gradle-development/learn/lecture/28264772#overview). +source code for following lectures: +- [Gradle Plugin Development - Binary Plugin](https://www.udemy.com/course/gradle-development/learn/lecture/28264772#overview) +- [Gradle Plugin Development - Publishing - Local Maven Repository](https://www.udemy.com/course/gradle-development/learn/lecture/29080272#overview) To successfully create a plugin you should: - Import `java-gradle-plugin` core Gradle plugin @@ -24,6 +26,19 @@ to proof that the plugin is applied. In order that plugin descriptor will be generated you have to specify plugins inside the `gradlePlugin{}` block. +## Publishing + +To be able to publish plugin to a Maven repository you have to apply `maven-publish` plugin, which will give you ability +of artifact publication. + +### Local Maven Publishing + +To publish compiled plugin to Local Maven repository you have to run task `publishToMavenLocal`. As a result this plugin will +be published to `{user-home}/.m2/repository/com/rivancic/greeting-plugin` directory. + +To be able to refenrece this plugin from withing a project you will have to define Local Maven repository inside of +`pluginManagement{}` block in `settings.gradle` file. + ## Resources diff --git a/binary-plugin/binary-plugin-example/build.gradle b/binary-plugin/binary-plugin-example/build.gradle index 41324a8..b964bff 100644 --- a/binary-plugin/binary-plugin-example/build.gradle +++ b/binary-plugin/binary-plugin-example/build.gradle @@ -1,10 +1,17 @@ /** - * Core Java Gradle Plugin. It simplifies - * compilation and publishing of Gradle binary plugins. + * java-gradle-plugin - Core Gradle Plugin, Java Gradle Plugin. + * It simplifies compilation and publishing of Gradle binary plugins. * + * maven-publish - Core Gradle Plugin, Java Gradle PluginMaven Publish + * plugin will make it possible to publish artifacts to Maven repositories. + * + * com.rivancic.greeting-plugin - if uncommented will apply itself to the Gradle build. It's meant to test the + * functionality of the plugin in project itself. */ plugins { id 'java-gradle-plugin' + id 'maven-publish' + // id 'com.rivancic.greeting-plugin' version '0.1.0' // Can be applied after its published to local or private/remote plugin repository } group 'com.rivancic' diff --git a/binary-plugin/binary-plugin-example/settings.gradle b/binary-plugin/binary-plugin-example/settings.gradle index 1062d9e..a49d15f 100644 --- a/binary-plugin/binary-plugin-example/settings.gradle +++ b/binary-plugin/binary-plugin-example/settings.gradle @@ -1,2 +1,18 @@ +/** + * By default only Gradle Plugin Portal is defined as a repository that provides Gradle plugins that can be applied + * within
plugins{}
 block.
+ *
+ * If you want to specify any additional repository you have to define them in pluginManagement block within
+ * setting.gradle file. Remember pluginManagement has to be the first statement inside settings.gradle file.
+ *
+ * In definition below both Gradle Plugin Portal and Maven Local repository will be taken into account when Gradle
+ * will search for defined plugin by its ID and version.
+ */
+pluginManagement {
+  repositories {
+    gradlePluginPortal()
+    mavenLocal()
+  }
+}
 rootProject.name = 'binary-plugin-example'