1

I want to install submodules of my project as jar to maven local repository. I searched a gradle script for publish. I found. But it install only one jar and it has not classes of submodules. How can I proceed?

               my-project
               |
               |__subprj1
               |  |__src
               |     |__ com
               |        |__Abc.java
               |   
               |  |__pom.xml
               |__subprj2
               |  |
               |  |__pom.xml
               |
               |__ build.gradle
               |__ publish.gradle

build.gradle:

apply plugin: "java"
        apply from : 'publish.gradle'

        ext {
            GROUPID = "my-project"
            VERSION = "1.0.0"
            robovmVersion = "1.5.0"
            androidVersion = "4.4"
            gwtVersion = "2.6.0"
            jglfwVersion = "1.1"
            lwjglVersion = "2.9.2"
            jlayerVersion = "1.0.1-gdx"
            jorbisVersion = "0.0.17"
            junitVersion = "4.11"
        }

        buildscript {
            repositories { mavenCentral() }
            dependencies {
                classpath "com.android.tools.build:gradle:1.2.3"
                classpath "org.robovm:robovm-gradle-plugin:1.5.0"
            }
        }

        configure(allprojects - project('...'')) {
            apply plugin: "eclipse"
            apply plugin: "idea"
            apply plugin: "java"

            compileJava.options.encoding = 'UTF-8';

            repositories {
                mavenCentral()
                maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
            }

            group = GROUPID
            version = VERSION

            // set source Java version
            sourceCompatibility = 1.6
            targetCompatibility = 1.6
            sourceSets.main.java.srcDirs = ["src"]
            sourceSets.main.resources.srcDirs = ["src"]

            // create a custom configuration for local dependencies such as Android runtime
            configurations {
                optional
                compile.extendsFrom optional
            }
        }

        project("...) {

        }


        if (JavaVersion.current().isJava8Compatible()) {
            allprojects {
                tasks.withType(Javadoc) {
                    options.addStringOption("Xdoclint:none", "-quiet")
                }
            }
        }

        task fetchNatives << {
            ant.importBuild "fetch.xml"
            fetch.execute()
            copy.execute()
        }

publish.gradle:

    apply plugin: 'maven'
    apply plugin: 'signing'

    group = 'my-project'
    version = '1.0.0'
    ext.packaging = 'jar'

    def isDevBuild
    def isCiBuild
    def isReleaseBuild

    def sonatypeRepositoryUrl

    //set build variables based on build type (release, continuous integration, development)
    if(hasProperty("release")) {
        ...
    } else if (hasProperty("snapshot")) {
        ...
    } else {
        isDevBuild = true
        println "Performing local build"
    }

    repositories {
        mavenCentral()
    }

    task artifactDocs(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from 'build/docs/javadoc'
    }

    task artifactSources(type: Jar) {
        from sourceSets.main.allSource
        classifier = 'sources'
    }

    artifacts {
        archives jar
        archives artifactDocs
        archives artifactSources
    }

    if(isReleaseBuild) {
        signing {
            sign configurations.archives
        }
    } else {
        task signArchives {
            // do nothing
        }
    }

    uploadArchives {
        repositories {
            if (isDevBuild) {
                mavenLocal()
            }
        }
    }
Burak Dağlı
  • 512
  • 2
  • 10
  • 33
  • May be try to make your subprj1 and subprj2 gradle-subprojects for my-project, then they both will have it's own build.gradle files and can be easily executed from parens build script – Stanislav Sep 18 '15 at 11:51

1 Answers1

0

First, your submodules must be handled as gradle subprojects. So you have to create build.gradle files for them and include them in the root project via settings.gradle file.

Second, in the build.gradle file of each subproject, you can define your deployment code. To install something in your local maven repository ($HOME/.m2), I use the gradle maven plugin. After configuring it correctly, I run install on this subproject:

gradle subproject1:install

Here an example configuration of such a subproject to install it locally:

apply plugin: 'maven'
...
group = 'com.example.subproject2'

configurations {
    deployerJars
}

dependencies {
    ... 
    deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
...
def installer = install.repositories.mavenInstaller
Sebi
  • 8,323
  • 6
  • 48
  • 76