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

 月光女孩2602906135_166 发布于 2023-02-07 14:06

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

这是我的项目布局:

project LeftArm:生成一个jar文件

project RightArm:生成一个jar文件

project AllArms:依赖项目LeftArmRightArm并生成一个war文件

当我在AllArms项目中运行'gradle build uploadArchives'时,它会构建LeftArmRightArm项目,但它不会将jar文件(由LeftArmRightArm项目生成)上传到本地Maven 仓库.

这是我的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'
        }
    }
    }
}

...

project AllArms:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'eclipse'

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

def gwtVersion = '2.2.0'

repositories
{
    mavenLocal()
    mavenCentral()
}

dependencies
{
    compile project(':LeftArm') 
    compile project(':RightArm') 
    // ###   NOTE:  this is where the build breaks b/c uploadArchives task is not executed  ###
    compile group: group, name: 'LeftArm', version:version
    compile group: group, name: 'RightArm', version:version
    providedCompile group: 'javax.validation', name:'validation-api', version:'1.0.0.GA'
    providedCompile group: 'javax.validation', name:'validation-api-sources', version:'1.0.0.GA'
    providedCompile group: 'com.google.gwt', name:'gwt-user', version:gwtVersion
    providedCompile group: 'com.google.gwt', name:'gwt-dev', version:gwtVersion
    providedCompile group: 'org.gwtext', name:'gwtext', version:'2.0.4'
}

task compileGwt (dependsOn: classes, type: JavaExec) {
    project.ext 
    {
    gwtDir = "${project.buildDir}/gwt"
    extraDir = "${project.buildDir}/extra"
    gwtModuleName = 'MyModuleName'
    }
    inputs.source sourceSets.main.java.srcDirs
    inputs.dir sourceSets.main.output.resourcesDir
    outputs.dir project.gwtDir

    // Workaround for incremental build (GRADLE-1483)
    outputs.upToDateSpec = new org.gradle.api.specs.AndSpec()

    doFirst
    {
    file(project.gwtDir).mkdirs()
    }

    main = 'com.google.gwt.dev.Compiler'

    classpath
    {
    [
        sourceSets.main.java.srcDirs,           // Java source
        sourceSets.main.output.resourcesDir,    // Generated resources
        sourceSets.main.output.classesDir,      // Generated classes
        sourceSets.main.compileClasspath,       // Deps
    ]
    }

    args =
    [
    project.gwtModuleName, // Your GWT module
    '-war', project.gwtDir,
    '-logLevel', 'INFO',
    '-localWorkers', '2',
    '-compileReport',
    '-extra', project.extraDir,
    ]

    maxHeapSize = '256M'
}

buildscript 
{
    repositories 
    {
    mavenLocal()
    }
}

sourceSets 
{
    main 
    {
    resources 
    {           srcDir('src/main/java').include('**/client/**').include('**/public/**').include('**/*.gwt.xml')
    }
    }
}

war.dependsOn(compileGwt)
war 
{
    def gwtOutputTree = project.fileTree(project.gwtDir)
    from(gwtOutputTree)
    baseName = artifactId
}

task classesJar(type: Jar) {
    dependsOn(classes)
    baseName = artifactId
}

artifacts 
{
    archives war, classesJar
}

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('war') 
        { 
            artifact, file -> artifact.ext == 'war'
        }
    }
    }
}

Peter Nieder.. 5

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

1 个回答
  • uploadArchives并不意味着用于安装到本地Maven存储库.相反,使用该install任务.

    2023-02-07 14:08 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有