我试图弄清楚如何在gradle中使用ivy依赖项,并让它只从存储库下载jar文件 . 现在,我得到了javadocs和各种源档案的zip文件,这在我的war文件中造成了不必要的膨胀 .

我是新手,慢慢地试图将我的 Ant 任务/常 Spring 藤转换成它 .

谢谢 . 这是我的build.gradle的副本

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'project-report'

// Loads additional gradle file, in this case loading a properties file
apply from: 'external_properties.gradle'

// Set so that we can use our current folder structure
sourceSets {
    main.java.srcDirs += 'src/java'
    main.resources.srcDirs += 'src/resources'
}

subprojects {
    tasks.withType(Javadoc).all { enabled = false }
}

// Our declared repositories
repositories {
    maven {
        url "https://maven.java.net/content/groups/public"
        url "http://repository.jboss.com/maven2"
        url "https://repo1.maven.org/maven2"
    }

    ivy {
        url "${ivy_repository_url}"
        layout "pattern", {
            ivy "repository/[organisation]/[module]/[revision]/ivy.xml"
            artifact "repository/[organisation]/[module]/[revision]/[artifact].[ext]"
            m2compatible = true
        }
        credentials {
            username "${ivy_repository_username}"
            password "${ivy_repository_password}"
        }
    }
}

// This is for getting the revision number from our build
buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath('at.bxm.gradleplugins:gradle-svntools-plugin:latest.release')
    }
}
apply plugin: "at.bxm.svntools"

allprojects{
    ext.project_version = 'r' + "$svntools.version"
}


configurations.runtime {
    exclude group: 'javax.management'
    exclude group: 'javax.mail'
    exclude group: 'javax.activation'
    exclude group: 'javax.jms'
}

dependencies {
    compile fileTree(dir: "${projectDir}/lib", include: '*.jar')
    compile fileTree(dir: "${projectDir}/compsciBuild/lib", include: '*.jar')

    compileOnly 'commons-io:commons-io:2.5'
    compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
    compile 'cglib:cglib:2.2.2'
    compileOnly 'net.sourceforge.jtidy:jtidy:r938'
    compile 'org.hibernate:hibernate-core:5.2.9.Final'
    compile 'org.hibernate:hibernate-c3p0:5.2.9.Final'
    compile 'org.hibernate.common:hibernate-commons-annotations:5.0.1.Final'
    compileOnly('org.hibernate:hibernate-tools:5.2.3.Final') {
        exclude module: 'jtidy'
        exclude module: 'freemarker'
        exclude module: 'c3p0'
    }
    compileOnly 'com.mysql:mysql-connector-java:5.1.7'
    compile('com.enigmastation:ci-bayes:1.0.6.9') {
        exclude group: 'org.hibernate', module: '*'
        exclude group: 'org.springframework', module: 'spring'
    }
    compileOnly 'net.sf.ezmorph:ezmorph:1.0.6'
    compileOnly 'net.sf.json-lib:json-lib:2.3.0.3'
    compile 'com.compsciresources:TaxonomyDigest:r24609'
    compile 'com.compsciresources:TaxonomySearch:r24042'
    compile('com.compsciresources:XBRLImport:r24039') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compile 'com.compsciresources:XBRLReports:r24059'
    compileOnly('com.compsciresources:uploadProcessor:r24146') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compileOnly('com.compsciresources:htmlCleaner:r25243') {
        exclude group: 'org.apache.commons', module: 'commons-io'
        force = true
    }
    compileOnly 'org.apache.commons:commons-codec:1.10'
    compileOnly 'org.apache.commons:commons-text:1.1'
    compileOnly 'org.springframework:spring-core:4.3.5.RELEASE'
    compileOnly 'org.springframework:spring-orm:4.3.5.RELEASE'
    compileOnly 'org.springframework:spring-web:4.3.5.RELEASE'
    compileOnly 'org.springframework:spring-context-support:4.3.5.RELEASE'
    compileOnly 'org.springframework:spring-test:4.3.5.RELEASE'
    compileOnly 'org.springframework.security:spring-security-web:4.2.2.RELEASE'
    compileOnly 'org.springframework.security:spring-security-acl:4.2.2.RELEASE'
    compileOnly 'org.springframework.security:spring-security-config:4.2.2.RELEASE'
    compileOnly 'org.springframework.security:spring-security-taglibs:4.2.2.RELEASE'
    compileOnly 'org.aspectj:aspectjrt:1.8.10'
    compileOnly('org.apache.xmlbeans:xmlbeans:2.6.0') {
        exclude group: 'javax.xml.stream', module: 'jsr173_api'
    }
    compileOnly 'log4j:log4j:1.2.17'
    compileOnly 'org.apache.jakarta.taglibs:standard:1.1.2'
    compileOnly 'net.htmlparser.jericho:jericho-html:latest.integration'
    compileOnly 'org.apache.struts:struts2-core:2.5.13'
    compileOnly('org.apache.struts:struts2-spring-plugin:2.5.13') {
        exclude group: 'org.springframework', module: '*'
    }
    compileOnly 'org.apache.struts:struts2-json-plugin:2.5.13'
    compileOnly 'org.codehaus.xstream:xstream:1.4.3.1'
    compileOnly('org.codehaus.woodstox:wstx-lgpl:latest.release') {
        exclude group: 'javax.xml.stream'
    }
    compileOnly 'org.apache.lucene:lucene-core:3.3.0'
    compileOnly('com.gargoylesoftware:htmlunit:2.7') {
        exclude group: 'org.apache.commons', module: 'commons-io'
    }
    compileOnly('org.apache.httpcomponents:httpclient:4.5.2') {
        force = true
    }
    compile 'com.google.guava:guava:22.0'
    compile('org.docx4j:docx4j:3.3.1') {
        exclude module: 'httpclient'
        exclude module: 'xalan'
        exclude module: 'commons-io'
        exclude module: 'guava'
    }
    compileOnly('org.docx4j:docx4j-ImportXHTML:3.3.1') {
        exclude module: 'httpclient'
        exclude module: 'xalan'
    }
    compileOnly 'org.dom4j:dom4j:1.6.1'
    testCompile 'xmlunit:xmlunit:1.2'
    testCompile 'org.easymock:easymock:3.0+'
    testCompile 'pl.pragmatists:JUnitParams:0.5.0+'
    testCompile 'org.mozilla:juniversalchardet:1.0.3'
    compileOnly 'net.jcip:jcip-annotations:1.0'
    compileOnly 'com.google.code.findbugs:jsr305:1.3.9'
    compileOnly 'com.google.code.findbugs:annotations:1.3.9'
    compileOnly('com.google.code.findbugs:findbugs:1.3.9'){
        exclude group: 'xml-apis'
        exclude group: 'xerces'
        exclude module: 'xalan'
     } 
    compileOnly 'net.bull:javamelody:1.45.0'
    compileOnly 'net.java.dev.jna:jna:3.4.0'
}

task copy_data(dependsOn: 'build'){
    doLast{
        // converted from data.copy-data
        copy{
            from "${base_data_dir}"
            into "${data_dir}"
            exclude('build/', 'build/**')
            includeEmptyDirs = false 
        }
        // converted from log4j.copy-data
        copy{
            from "${etc_dir}"
            into "${buildDir}/build-only"
            include('log4j.nonweb.properties')
            rename('log4j.nonweb.properties', 'log4j.properties')
            includeEmptyDirs = false 
        }
        // converted from log4j.copy-data
        copy{
            from "${etc_dir}"
            into "${build_webinf_dir}/classes"
            include('log4j.web.properties')
            rename('log4j.web.properties', 'log4j.properties')
            includeEmptyDirs = false 
        }
        // converted from mail.copy data, hibernate.copy-data and spring.copy-data
        copy{
            from "${etc_dir}"
            into "${classes_dir}"
            include('mail.properties','c3p0.properties','jdbc.properties','applicationContext*.xml','applicationResources.properties','htmlentities.properties','analytics.properties','options.properties','storage.properties','previewer.properties','branding.properties','docx4j.properties','diffHtmlHeader.xsl')
            exclude('applicationContext*.*.xml')
            includeEmptyDirs = false 
        }

        copy{
            from "${src_java_dir}" 
            into "${classes_dir}"
            include('**/*.ftl','**/*.so','**/*.dll','**/*.dylib','**/wkhtmltopdf*')
            includeEmptyDirs = false 
        }

        // copy from spring.copy-ic-specific-data
        if(project.hasProperty("taxonomy_selector")){
            copy{
                from "${etc_dir}"
                into "${classes_dir}"
                include('applicationContext-security.ts.xml')
                rename('applicationContext-security.ts.xml','applicationContext-security.xml')
                includeEmptyDirs = false 
            }
        }
        else{
            copy{
                from "${etc_dir}"
                into "${classes_dir}"
                include('applicationContext-security.ic.xml')
                rename('applicationContext-security.ic.xml','applicationContext-security.xml')
                includeEmptyDirs = false 
            }
        }

        copy{
            from "${src_java_dir}"
            into "${classes_dir}"
            include('**/*.properties','**/*.xml')
            includeEmptyDirs = false 
        }

        copy{
            from "${etc_dir}"
            into "${build_webapp_dir}/jsp"
            include('about.jsp')
            includeEmptyDirs = false 
        }

        copy{
            from "${etc_dir}"
            into "${buildDir}/build-only"
            include('serializer*.xml','verifier.xml')
            includeEmptyDirs = false 
        }

        copy{
            from "${branding_dir}/${branding_imageFolder}"
            into "${build_webapp_dir}/images/branding"
            include('*')
            includeEmptyDirs = false 
        }

        copy{
            from "${web_unprotected_dir}"
            into "${build_webapp_dir}"
            includeEmptyDirs = false 
        }

        copy{
            from "${com_dir}"
            into "${classes_dir}"
            includeEmptyDirs = false 
        }

        def temp_build = new File("${classes_dir}/java")
        temp_build.deleteDir()

        //Setting the tokens of mail.properties as loaded from the gradle.properties file
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_TRANSPORT_PROTOCOL@', value: mail_transport_protocol)
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_HOST@', value: mail_host)
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_AUTH@', value: mail_auth)
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_LOCALHOST@', value: mail_localhost)
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_AUTH_USERNAME@', value: mail_auth_username)
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_AUTH_PASSWORD@', value: mail_auth_password)
        ant.replace(file: "${classes_dir}/mail.properties", token: '@MAIL_CUSTOMER_SUPPORT@', value: mail_customer_support)

        //Setting the tokens of jdbc.properties as loaded from the gradle.properties file
        ant.replace(file: "${classes_dir}/jdbc.properties", token: '@JDBC_URL@', value: jdbc_url)
        ant.replace(file: "${classes_dir}/jdbc.properties", token: '@JDBC_USER@', value: jdbc_userid)
        ant.replace(file: "${classes_dir}/jdbc.properties", token: '@JDBC_PASS@', value: jdbc_password)
        ant.replace(file: "${classes_dir}/jdbc.properties", token: '@JDBC_DRIVER_CLASS@', value: jdbc_driver_class)
        ant.replace(file: "${classes_dir}/jdbc.properties", token: '@JDBC_POOL_SIZE@', value: jdbc_pool_size)

        //Setting the tokens for analytics.properties
        ant.replace(file: "${classes_dir}/analytics.properties", token: '@ANALYTICS_ID@', value: analytics_id)

        //Setting the tokens for options.properties
        ant.replace(file: "${classes_dir}/options.properties", token: '@DEVELOPER_MODE@', value: options_developerMode)
        ant.replace(file: "${classes_dir}/options.properties", token: '@GENERATE_CORPUS@', value: options_generateCorpusOnXBRLDownload)
        ant.replace(file: "${classes_dir}/options.properties", token: '@WATERMARKS@', value: options_watermarks)
        ant.replace(file: "${classes_dir}/options.properties", token: '@INLINE_ALLOWED@', value: options_inlineAllowed)
        ant.replace(file: "${classes_dir}/options.properties", token: '@INLINE_DATE@', value: options_inlineDeploymentDate)
        ant.replace(file: "${classes_dir}/options.properties", token: '@DQCWEBSERVICEURL@', value: dqc_webservice_url)

         //Setting the tokens for storage.properties       
        ant.replace(file: "${classes_dir}/storage.properties", token: '@STORAGE_LOCATION@', value: storage_location)

        //Setting the tokens for previewer.properties       
        ant.replace(file: "${classes_dir}/previewer.properties", token: '@RENDERER_SERVICE_URL@', value: renderer_service_url)

        //Setting the tokens for branding.properties       
        ant.replace(file: "${classes_dir}/branding.properties", token: '@BRANDING_IMAGEFOLDER@', value: branding_imageFolder)

        ant.replace(file: "${build_webapp_dir}/jsp/about.jsp", token: '@VERSION_NUMBER@', value: project_version)
    }
}

task copy_hibernate_cfg_xml{
    doLast{
        copy{
            from "${etc_dir}"
            into "${classes_dir}"
            include('hibernate.cfg.xml')
            includeEmptyDirs = false 
        }

        //Setting the tokens of hibernate.cfg.xml as loaded from the gradle.properties file
        ant.replace(file: "${classes_dir}/hibernate.cfg.xml", token: '@JDBC_URL@', value: jdbc_url)
        ant.replace(file: "${classes_dir}/hibernate.cfg.xml", token: '@JDBC_USER@', value: jdbc_userid)
        ant.replace(file: "${classes_dir}/hibernate.cfg.xml", token: '@JDBC_PASS@', value: jdbc_password)
        ant.replace(file: "${classes_dir}/hibernate.cfg.xml", token: '@JDBC_DRIVER_CLASS@', value: jdbc_driver_class)
        ant.replace(file: "${classes_dir}/hibernate.cfg.xml", token: '@JDBC_POOL_SIZE@', value: jdbc_pool_size)
    }
}

task copy_log4j{
    doLast{
        copy{
            from "${etc_dir}"
            into "${build_webinf_dir}/classes"
            include('log4j.web.properties}')
            rename('log4j.web.properties}','log4j.properties')
        }
        ant.replace(file: "${build_webinf_dir}/classes/log4j.properties", token: '@APP_NAME@', value: app_name)
    }
}

task war_dist(dependsOn:[copy_data,copy_hibernate_cfg_xml,copy_log4j]){
    doLast{
        copy{
            from "${classes_dir}"
            into "${build_webinf_dir}/classes"
            includeEmptyDirs = false 
        }
        copy{
            from "${etc_dir}"
            into "${build_webinf_dir}"
            include('web.xml','decorators.xml')
            includeEmptyDirs = false 
        }
        copy{
            from "${etc_dir}"
            into "${build_webinf_dir}/tld"
            include('*.tld')
            includeEmptyDirs = false 
        }
        copy{
            from "${web_protected_dir}"
            into "${build_webinf_dir}"
            exclude('**/*.jsp')
            includeEmptyDirs = false 
        }
        copy{
            from "${web_protected_dir}"
            into "${build_webinf_dir}/jsp"
            include('**/*.jsp')
            includeEmptyDirs = false 
        }
        copy{
            from "${web_unprotected_dir}"
            into "${build_webinf_dir}"
            include('*')
            includeEmptyDirs = false 
        }

        // Converted from services.ant
        copy{
            from "${services_dir}"
            into "${classes_dir}/META-INF/services"
            include('*')
            includeEmptyDirs = false
        }

        // Converted from struts.ant
        copy{
            from "${etc_dir}"
            into "${build_webinf_dir}/classes"
            include('struts.xml','struts.properties','xwork-conversion.properties','validators.xml')
        }

        delete fileTree("${classes_dir}}"){
            include('applicationContext*.xml','applicationResources.properties')
        }
    }
}

task build_war(type: War, dependsOn:[war_dist]){
    archiveName "${app_name}.war"
    destinationDir = file("${dist_dir}")
    from "${build_webapp_dir}"
    from("${etc_dir}"){
        include "context.xml"
        into('META-INF')
    }
}

task clean_cache {
    def home_dir = System.getProperty("user.home")
    def cache = new File("${home_dir}/.gradle/caches")
    doLast{
        cache.deleteDir()
    }
}