Adding a spring boot project into local maven repository

Viewed 179

I have created a gradle project ie MicroTwo which has a child module known as transferObject

settings.gradle for the parent module

    rootProject.name = 'microtwo'
     include 'transferObjects'

build.gradle for MicroTwo

    plugins {
    id 'java'
}

group='com.micro'
version = '1.0.4'
sourceCompatibility = '11'


repositories {

    mavenLocal()
}

dependencies {
    implementation project(':transferObjects')
}

build.gradle for child module ie transferObject is

    plugins {
    id 'java'
}

group = 'com.micro'

I want to add the child module ie transferObject as a jar in my local maven repository so that I can use it as a external jar in another spring boot project

1 Answers

From the gradle documentation gradlepublish

We need to add a maven-publish plugin like

plugins {

          id 'maven-publish'
         id 'java-library'

          }

and define a publishing block

group 'com.test'
version '1.0.5'

        publishing {
                    publications {
                 myLibrary(MavenPublication) {
                      from components.java
                        }
                    }

The plugin block and publish block should be added in the build.gradle of the module for which you want to create a jar. Adding the plugin maven-publish will create tasks like

publishPubNamePublicationToMavenLocal

or

publishPubNamePublicationToRepoNameRepository

running publishPubNamePublicationToMavenLocal will create the jar in your local m2 repository in my case I got a jar transferObjects-1.0.5 inside com\test\transferObjects\1.0.5 folder

Related