【问题标题】:Gradle maven-publish how to use for multiple projectsGradle maven-publish 如何用于多个项目
【发布时间】:2014-07-11 20:10:14
【问题描述】:

可能是我无法找到合适的组合键来从谷歌中找到这个。

环境:Gradle 2.0

参考文档http://www.gradle.org/docs/current/userguide/publishing_maven.html

我有一个像

这样的 gradle flat 多级项目
root:
  -project1
  -project2

使用plugin: 'maven-publish' 我想将单个项目安装到maven local repo。 但是,当我尝试执行 publishToMavenLocal 任务时,它会创建 jar 但该 jar 没有任何 class files

每个单独的项目都有源文件夹src/api/javasrc/impl/java我想单独安装apiimll,如果单个捆绑也可以。

以下是我当前的build.gradle 文件内容:

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'
    }
}

项目 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'
          }
    }
}

请帮助我,如果我遗漏了什么或者我完全走错了学习 Gradle 的道路。

【问题讨论】:

    标签: java gradle build.gradle


    【解决方案1】:

    每个单独的项目都有源文件夹作为 src/api/java 和 src/impl/java

    默认情况下,Gradle 期望你的主源文件夹是 src/main/java,如果你想把它放在不同的地方你需要告诉 gradle 它在​​哪里 as explained in the user guide

    【讨论】:

    • 感谢您的提示,在定义源文件夹(如 api 和 impl)后,它的工作正常
    猜你喜欢
    • 2018-07-06
    • 1970-01-01
    • 2015-05-03
    • 2018-07-11
    • 1970-01-01
    • 2017-11-01
    • 2021-03-31
    • 2013-02-01
    • 2015-05-03
    相关资源
    最近更新 更多