仅在gradle中上传war / jar文件(限制zip / tar生成和上传)

时间:2015-11-18 08:14:49

标签: gradle upload

我的构建脚本如下所示。我使用gradle build命令构建和gradle upload命令来上传工件。我的问题是tar,zip文件也是用这个命令生成的并且上传了。我不想要它。只有我想上传的内容是'jar'和'war'文件。 我昨天也发了一个相关的问题here

更多详细信息(我已排除了一些不需要的代码)

在root中构建文件

allprojects  {
  apply plugin: 'maven'
 group = 'groupid'
version = '1.0-SNAPSHOT'
}

subprojects {
  apply plugin: 'java'
  sourceCompatibility = 1.7
  targetCompatibility = 1.7


    repositories {
        maven {
            credentials {
                username "$nexusUser"
                password "$nexusPass"
            }
            url "$nexusUrl"
        }
    }

    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "$nexusSnapshotUrl") {
                    authentication(userName: "$nexusUser", password: "$nexusPass")
                }
            }
        }
    }
}

ext.comlib = [ // Groovy map literal
                  junit3: "junit:junit:3.8",
                  junit4: "junit:junit:4.9",
                  spring_core: "org.springframework:spring-core:3.1",
                  hibernate_validator : "org.hibernate:hibernate-validator:5.1.3.Final",
                  spring_core : "org.springframework.security:spring-security-core:4.0.2.RELEASE",
                  spring_security_web: "org.springframework.security:spring-security-web:4.0.2.RELEASE",
                  spring_security_config: "org.springframework.security:spring-security-config:4.0.2.RELEASE",
                  spring_boot_starter_test: "org.springframework.boot:spring-boot-starter-test:1.2.5.RELEASE",
                  spring_boot_starter_actuator: "org.springframework.boot:spring-boot-starter-actuator:1.2.5.RELEASE",
                  spring_boot_plugin_gradle: "org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE",
                  asciidoctor_gradle_plugin: "org.asciidoctor:asciidoctor-gradle-plugin:1.5.1",
                  asciidoctor_pdf_plugin: "org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.9"/*,
                  sl4j_api: "org.slf4j:slf4j-api:1.7.12",
                  sl4j_log4j: "org.slf4j:slf4j-log4j12:1.7.12",
                  logback_classic: "ch.qos.logback:logback-classic:1.1.3",
                  logback_core: "ch.qos.logback:logback-core:1.1.3"*/
]

在子模块中构建文件

apply plugin: 'spring-boot'
group = 'com.group.id'
apply from: "../build.gradle"
apply plugin: 'org.asciidoctor.gradle.asciidoctor'

apply plugin: 'war'

description = 'module name'
dependencies {
    compile "someothermodule:commonapi:1.0.0-SNAPSHOT"
    compile "io.springfox:springfox-swagger2:2.0.1"
    compile project(':dependingproject1:dependingproject2')
    compile comlib.spring_boot_starter_actuator
    compile comlib.spring_core
    compile comlib.spring_security_web
    compile comlib.spring_security_config
    testCompile(comlib.spring_boot_starter_test) {
exclude(module: 'commons-logging')
    }
    testCompile comlib.junit4
    providedCompile comlib_app.spring_boot_plugin_tomcat
    testCompile "io.springfox:springfox-staticdocs:2.0.3"
    testCompile "org.springframework:spring-test:4.1.7.RELEASE"
}

ext {
    swaggerOutputDir = file("src/docs/asciidoc/generated")
    asciiDocOutputDir = file("${buildDir}/asciidoc")
}

test {
    systemProperty 'org.springframework.restdocs.outputDir', asciiDocOutputDir
    systemProperty 'io.springfox.staticdocs.outputDir', swaggerOutputDir

}

//spring boot plugin
buildscript {
    repositories {
        maven {
            credentials {
                username "$nexusUser"
                password "$nexusPass"
            }
            url "$nexusCentral"
        }
        maven {
            credentials {
                username "$nexusUser"
                password "$nexusPass"
            }
            url "$nexusThirdParty"

        }
    }
    dependencies {
        classpath(comlib.spring_boot_plugin_gradle)
    }
}

3 个答案:

答案 0 :(得分:3)

在我的gradle文件中包含以下代码段

[distZip, distTar].each { task -> configurations.archives.artifacts.removeAll
{ it.class.simpleName == "ArchivePublishArtifact" && it.archiveTask == task }

task.enabled = false
}

有关详细信息,请参阅this link。它与spring boot插件有关。

答案 1 :(得分:0)

或多或少与ajuncc的解决方案相同,但也许更简单一些。从存档配置中删除所有.tar工件:

configurations.archives.artifacts.removeAll {PublishArtifact publishArtifact -> publishArtifact.type == 'tar'} 

答案 2 :(得分:0)

arjuncc的解决方案似乎无法在Gradle 4.10.2上使用,因此这是一个可以使用并使用公共API的解决方案,希望它可以继续使用。

configurations.archives.artifacts.removeAll {
    // exclude from the archives configuration all artifacts that were generated by distZip & distTar
    def depTasks = it.getBuildDependencies().getDependencies()
    depTasks.contains(distZip) || depTasks.contains(distTar)  
}