如何告诉gradle构建并将依赖项目的档案上传到本地maven

时间:2013-12-30 21:18:47

标签: gradle multi-project

我有一个多项目问题,Gradle的文档没有任何信息(也无法在stackoverflow上找到)。任何帮助/指导将不胜感激。

以下是我的项目布局:

  • project LeftArm :生成一个jar文件
  • project RightArm :生成一个jar文件
  • 项目 AllArms :取决于项目 LeftArm RightArm 并生成war文件

当我在 AllArms 项目中运行'gradle build uploadArchives'时,它会构建 LeftArm RightArm 项目,但它不会上传{ {1}}文件(由 LeftArm RightArm 项目生成)到本地Maven仓库。

以下是我的jar文件:

build.gradle

...

project LeftArm:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'

ext.artifactId = 'LeftArm'
archivesBaseName = ext.artifactId // sets filename of warfile/jarfile output
group = 'mygroup'
version = '1.0'

buildscript 
{
    repositories 
    {
    mavenLocal()
    }
}

jar 
{
    from(sourceSets['main'].allJava)
}

dependencies 
{
    compile group: 'javax.validation', name:'validation-api', version:'1.0.0.GA'
    compile group: 'javax.validation', name:'validation-api-sources', version:'1.0.0.GA'
}

def localRepoURL = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath

// NOTE: this project will publish to the local Maven repo.
uploadArchives 
{
    repositories 
    {
    mavenDeployer 
    {
        repository(url: localRepoURL)
        addFilter('jar') 
        { 
            artifact, file -> artifact.ext == 'jar'
        }
    }
    }
}

...

project RightArm:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'

ext.artifactId = 'RightArm'
archivesBaseName = ext.artifactId // sets filename of warfile/jarfile output
group = 'mygroup'
version = '1.0'

buildscript 
{
    repositories 
    {
    mavenLocal()
    }
}

jar 
{
    from(sourceSets['main'].allJava)
}

dependencies 
{
    compile group: 'javax.validation', name:'validation-api', version:'1.0.0.GA'
    compile group: 'javax.validation', name:'validation-api-sources', version:'1.0.0.GA'
}

def localRepoURL = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath

// NOTE: this project will publish to the local Maven repo.
uploadArchives 
{
    repositories 
    {
    mavenDeployer 
    {
        repository(url: localRepoURL)
        addFilter('jar') 
        { 
            artifact, file -> artifact.ext == 'jar'
        }
    }
    }
}

1 个答案:

答案 0 :(得分:5)

uploadArchives并不意味着用于安装到本地Maven存储库。相反,请使用install任务。