首页 > 解决方案 > 如何离线创建本地 gradle 存储库,以便无需访问互联网?

问题描述

我正在使用Gradle 5.6.2,并且我有一个如下所示的 build.gradle 文件:

plugins {
    id 'java'
    id 'war'
    id 'groovy'
    id "org.gretty" version "2.3.1"
}

ext {
    warName = 'producer-ws'
    clientKeyStore = "$projectDir/certs/testclient.jks"
    serverKeyStore = "$projectDir/certs/testserver.jks"
    trustStore = "$projectDir/certs/testtruststore.jks"
}

dependencies {
    modules {
        // use servlet-api 2.5 which has a diff module name
        module("javax.servlet:javax.servlet-api") {
            replacedBy("javax.servlet:servlet-api")
        }

        module('org.codehaus.woodstox:woodstox-core-asl') {
            replacedBy('com.fasterxml.woodstox:woodstox-core')
        }
    }

    implementation parent

    implementation 'com.google.inject:guice:4.2.2'
    implementation 'com.typesafe:config:1.3.3'

    implementation 'ch.qos.logback:logback-classic:1.2.3'
    implementation 'org.slf4j:slf4j-api:1.7.26'

    implementation "org.apache.cxf:cxf-rt-features-logging:$cxfLibVersion"
    implementation "org.apache.cxf:cxf-rt-frontend-jaxws:$cxfLibVersion"
    implementation "org.apache.cxf:cxf-rt-transports-http:$cxfLibVersion"
    implementation "org.apache.cxf:cxf-rt-ws-addr:$cxfLibVersion"
    implementation "org.apache.cxf:cxf-rt-ws-policy:$cxfLibVersion"
    implementation "org.apache.cxf:cxf-rt-ws-rm:$cxfLibVersion"
    implementation "org.apache.cxf:cxf-rt-ws-security:$cxfLibVersion"

    providedCompile 'javax.servlet:servlet-api:2.5'


    testImplementation 'org.codehaus.groovy:groovy-all:2.5.6'
    testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
    testImplementation 'org.spockframework:spock-guice:1.3-groovy-2.5'
    testImplementation project(path: ':', configuration: 'testArtifacts')
}


tasks.named('war').configure {
    baseName = warName
    version = ''

    webInf {
        from("${parent.projectDir}/${wsdlDir}") {
            into('classes/wsdl')
        }
    }
}

tasks.named('test').configure {
    description = 'Runs integration tests against a test CXF producer.'
    group = 'verification'

    jvmArgs = [
            "-Djavax.net.ssl.keyStore=$clientKeyStore",
            '-Djavax.net.ssl.keyStorePassword=changeit',
            '-Djavax.net.ssl.keyStoreType=JKS',
            "-Djavax.net.ssl.trustStore=$trustStore",
            '-Djavax.net.ssl.trustStorePassword=changeit',
            '-Djavax.net.ssl.trustStoreType=JKS'
    ]

    dependsOn('appWarBeforeIntegrationTest')
    finalizedBy('appStop')
}

gretty {
    contextPath = warName
    servletContainer = 'jetty9.4'
    scanInterval = 0
    httpsEnabled = true
    httpEnabled = false
    sslKeyStorePath = serverKeyStore
    sslKeyStorePassword = 'changeit'
    sslTrustStorePath = trustStore
    sslTrustStorePassword = 'changeit'

    jvmArgs = [
            "-DjsdReferenceConsumer.ws.keystore.file=$serverKeyStore",
            "-DjsdReferenceConsumer.ws.truststore.file=$trustStore",
    ]
}

tasks.register('appWarBeforeIntegrationTest', org.akhikhl.gretty.AppBeforeIntegrationTestTask) {
    inplace = false

    dependsOn('war')
    finalizedBy('appStop')
}

project.afterEvaluate {
    tasks.named('appWarBeforeIntegrationTest').configure {
        /**
         * Gretty does not use a proper up-to-date check for StartBaseTask - partly because it is difficult to do.
         * This code adds inputs/outputs to help it run at the same time as the 'test' task.  Do this in afterEvaluate
         * so that we can see the 'test' task fully configured.
         */

        def outputMarkerFile = file("${buildDir}/test-results/test/gretty-${name}.task")  // co-locate with test task outputs so we will know if they get cleared

        inputs.files(test.inputs.files)  // use same inputs as the test task
        outputs.upToDateSpec = new AndSpec()  // clear the default { false } upToDate check automatically created by StartBaseTask
        outputs.file(outputMarkerFile)  // marker output file, up-to-date checks require at least one output

        doLast {
            outputMarkerFile.createNewFile()
        }
    }

    tasks.named('appStop').configure {
        outputs.upToDateWhen {
            // couple the up-to-date check to the server container start task
            appWarBeforeIntegrationTest.state.upToDate
        }
    }
}

我还有一个名为“gradlew”的 gradle 包装文件,我像这样调用它:

./gradlew clean build distZip

它下载 gradle-5.6.2.zip 然后继续下载/安装一大堆库大约 8 分 30 秒,直到最终显示“构建成功”的消息。

我的问题:如何生成本地 gradle 存储库,以便在断开 Internet 访问时,“./gradlew clean build distZip”命令仍然有效?

标签: javagradle

解决方案


推荐阅读