在根级存储库中添加jcenter()会破坏我的构建

时间:2018-07-18 15:39:07

标签: docker gradle build.gradle gradle-plugin

我有一个带有Gradle构建脚本的项目,我添加了bmuschko/gradle-docker-plugin以在新构建中创建和推送图像。

但是,如果我没有在根级别存储库中指定jcenter(),那么我将无法使用该插件,但这会破坏我的构建,所以我有点迷失了。

如果我添加根级别jcenter(),它将失败,并显示以下内容:

  

无法解析配置':compileClasspath'的所有依赖项。

     

找不到com.sleepycat:je:7.0.6。在以下位置搜索:

           

需要的人:项目:> org.jpos:jpos:2.1.1

但是,如果我不添加它,我得到的是:

  

无法解析配置':dockerJava'的所有依赖项。

     

找不到com.aries:docker-java-shaded:3.1.0-rc-3。在以下位置搜索:

           

由以下人员要求:项目:

我应该构建受阴影处理的Java并将其包含在本地Maven存储库中吗?

这是脚本:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven {
            url = 'https://nexus.company.com/content/repositories/snapshots/'
            credentials {
                username 'na'
                password 'na'
            }
        }
    }
    dependencies {
        classpath group: 'com.company.gradle', name: 'cpmgradle', version: '0.1-SNAPSHOT'
        classpath 'com.bmuschko:gradle-docker-plugin:3.4.4'
    }
}

// ADDING THIS BREAKS MY BUILD BUT IS NECESSARY FOR DOCKER PLUGIN TO WORK
repositories {
    jcenter()
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.company.gradle.java'
apply plugin: 'com.bmuschko.docker-remote-api'

projectinfo {
    group = 'com.company.mesb'
    artifact = 'MESB'
    version = '1.29.DEV-SNAPSHOT'
    description = 'MESB'
    packaging = 'jar'
}

dependencies {
    compile 'org.jpos:jpos:2.1.1'
    compile 'org.jdom:jdom2:2.0.6'
    compile 'org.json:json:20140107'
    compile 'com.company.javasdk:JavaSDK:1.1.JDOM2-SNAPSHOT'
    compile 'com.company.javasdk:Base64:1.0'
    compile 'org.apache.wss4j:wss4j-ws-security-dom:2.0.3'
    compile 'org.apache.santuario:xmlsec:2.0.3'
    compile 'org.slf4j:slf4j-log4j12:1.7.10'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'org.bouncycastle:bcprov-jdk15on:1.54'
    compile 'org.bouncycastle:bcpkix-jdk15on:1.54'

    compile 'junit:junit:4.12'
    compile 'org.jsoup:jsoup:1.9.2'
    compile 'org.apache.commons:commons-lang3:3.4'

    compile 'com.ibm:mq:5.3.07'
    compile 'com.ibm:mq.pcf:5.3.07'
    compile 'com.ibm:mq.jmqi:5.3.07'
    compile 'com.ibm:mq.headers:5.3.07'
    compile 'com.ibm:mq.commonservices:5.3.07'
    compile 'com.ibm:connector:1.0.0'

    runtime 'jaxen:jaxen:1.1.6'
    runtime 'xalan:xalan:2.7.2'
    runtime 'org.postgresql:postgresql:8.0-311.jdbc3'
    runtime 'commons-logging:commons-logging:1.2'
}

compileJava {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    options.fork = true
    options.compilerArgs << '-XDignore.symbol.file'
    options.forkOptions.executable = 'javac'
}

task libs(type: Copy) {
    description = "Copies dependencies to the 'lib' directory of the deployment."
    def libsDir = new File("$buildDir", 'libs')
    libsDir.mkdirs()
    def dockerDir = new File("$buildDir", 'docker')
    dockerDir.mkdirs()
    from project.configurations.runtime
    into libsDir
}

task bundleZip(type: Zip) {
    from projectDir

    include 'xsl/**'
    include 'conf/**'
    include 'js/**'
    include 'test/**'
    include 'mesb.sh'

    from(tasks.libs.outputs) {
        include 'MESB*'
    }

    into project.projectinfo.version
}

tasks.bundleZip.dependsOn jar
tasks.bundleZip.dependsOn libs

def dockerUsername = project.properties['dockerUsername'] ?: ""
def dockerPassword = project.properties['dockerPassword'] ?: ""
docker {
    registryCredentials {
        username = dockerUsername
        password = dockerPassword
    }
}

task buildImage(type: com.bmuschko.gradle.docker.tasks.image.DockerBuildImage) {
    doFirst {
        copy {
            from "${buildDir}/libs/MESB-${projectinfo.version}.jar"
            into "${buildDir}/docker"
            rename { String fileName ->
                fileName.replace("-${projectinfo.version}", "")
            }
        }
        copy {
            from "docker/jdk/Dockerfile"
            into "${buildDir}/docker"
        }
        copy {
            from "xsl"
            into "${buildDir}/docker/xsl"
        }
        copy {
            from "conf"
            into "${buildDir}/docker/conf"
        }
        copy {
            from "test"
            into "${buildDir}/docker/test"
        }
        copy {
            from "${buildDir}/libs"
            into "${buildDir}/docker/libs"
        }
    }
    inputDir = project.file("${buildDir}/docker")
    tag = "company/mesb:${projectinfo.version}"
}
tasks.buildImage.dependsOn build

task pushImage(type: com.bmuschko.gradle.docker.tasks.image.DockerPushImage) {
    imageName = "company/mesb"
    tag = "${projectinfo.version}"
}
tasks.pushImage.dependsOn buildImage

artifacts {
    archives bundleZip
}

/* Remove the default JAR file from the uploaded artifacts */
configurations.archives.artifacts.with { archives ->
    def jarArtifact
    archives.each {
        if (it.file =~ 'jar') {
            jarArtifact = it
        }
    }
    remove(jarArtifact)
}

jar {
    dependsOn configurations.runtime
    manifest {
        attributes 'Main-Class': 'main.MESB'
    }
}

tasks.build.dependsOn libs

sourceSets {
    main {
        java {
            srcDir 'src'
        }
    }
}

2 个答案:

答案 0 :(得分:3)

显然,在应用插件部分解决了根存储库定义的移动。

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.company.gradle.java'
apply plugin: 'com.bmuschko.docker-remote-api'


repositories {
    jcenter()
    mavenCentral()
}

答案 1 :(得分:0)

不知道您是否已经解决问题,但是无论哪种方式...

我在以下方面遇到了类似的问题

  

无法解析配置':dockerJava'的所有依赖项。

     

找不到com.aries:docker-java-shaded:3.1.0-rc-3。

我们通过添加以下内容解决了该问题

repositories {
  maven { url "https://repo.spring.io/snapshot" }
  maven { url "https://repo.spring.io/milestone" }
}