简体   繁体   中英

Gradle maven-publish how to use for multiple projects

Might be I am not able to find the appropriate key combination to find out from google for this.

Env: Gradle 2.0

referenced Doc http://www.gradle.org/docs/current/userguide/publishing_maven.html

I have a gradle flat multi level project like

root:
  -project1
  -project2

using plugin: 'maven-publish' I want to install individual project into maven local repo . However when I tried to to execute publishToMavenLocal task, its creating jar but that jar doesn't have any class files .

each individual project has source folder as src/api/java and src/impl/java I want to install api and imll separate, if single bundled also its fine.

below are my current build.gradle file contents:

root:

subprojects {
    apply plugin: 'eclipse'
    apply plugin: "java"
    apply plugin: "maven"
    apply plugin: 'maven-publish'

    repositories {
       mavenCentral()
       mavenLocal()
    }

    dependencies {
        testCompile 'junit:junit:4.8.2'
    }

    group = 'com.xx.ws.api'
    version = '1.0'
    description = "Common Utils Test."
    targetCompatibility = "1.8"
    sourceCompatibility = "1.8"

    jar {
        manifest.attributes provider: 'test'
    }

    //Gradle Wrapper genrator
    task wrapper(type: Wrapper) {
        gradleVersion = '2.0'
    }
}

Project 1:

ext {
    jerseyVersion = "2.10.1"
}

group = "com.xx.ws.api"
version = 1.0

dependencies {
    compile project(':commonutil')
    compile 'commons-codec:commons-codec:1.5'

    compile 'commons-lang:commons-lang:2.6'
    compile (group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: jerseyVersion){
        exclude module: 'jersey-client'
        exclude module: 'javax.annotation-api'
        exclude module: 'validation-api'
        exclude module: 'aopalliance-repackaged'
        exclude module: 'javax.inject'
        exclude module: 'hk2-api'
        exclude module: 'hk2-locator'
        exclude module: 'hk2-utils'
        exclude module: 'tiger-types'
        exclude module: 'osgi-resource-locator'
        exclude module: 'jersey-guava'
        exclude module: 'jersey-container-servlet-core'
        exclude module: 'jersey-container-servlet'
        exclude module: 'jersey-common'
        exclude module: 'jersey-server'

    }
//  implCompile (group: 'org.glassfish.jersey.ext', name: 'jersey-spring3', version: jerseyVersion){
//          //excluding a particular transitive dependency:
//          //exclude module: 'cglib' //by artifact name
//          exclude group: 'org.springframework' //by group
//          //exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
//      }

    testCompile 'junit:junit:4.10'
}

task sourceJar(type: Jar) {
  classifier "source"
}

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
            //artifact sourceJar // Publish the output of the sourceJar task
            //artifact source: sourceJar, classifier: 'src', extension: 'zip'
          }
    }
}

Please help me with, If I am missing anything or I am completely in wrong path to learn Gradle.

each individual project has source folder as src/api/java and src/impl/java

By default, Gradle expects your main source folder to be src/main/java , if you want to put it in a different place you need to tell gradle where it is as explained in the user guide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM