如何在gradle文件夹中下载jar文件和pom文件?

时间:2019-05-23 02:38:30

标签: eclipse gradle jar pom.xml

我将compile 'org.apache.commons:commons-vfs2-project:2.3'添加到我的build.gradle文件中,但发现有~\.gradle\caches\modules-2\files-2.1\org.apache.commons\commons-vfs2-project\2.3\860b837e62ab6d3282e7ff96f63ea21aebcdba40\commons-vfs2-project-2.3.pom,如何下载jar文件?

1 个答案:

答案 0 :(得分:1)

这是解决方案之一。 以下是示例项目的build.gradle
我包括2个插件和编写脚本,以在构建jar时包含其他脚本。
有一些我没有删除过的eclipse生成脚本。

apply plugin: 'java'

/**Following plugins are needed */

apply plugin: 'maven-publish' 
apply plugin: 'maven'

/**Just to include jar versioning*/
version = '1.0.0'

repositories {
    jcenter()
}

dependencies {

    compile 'org.slf4j:slf4j-api:1.7.25'
    testCompile 'junit:junit:4.12'
}




apply plugin: 'eclipse'

eclipse {    
  classpath {
    downloadSources = true // default: true
    downloadJavadoc = true // default: false
  }
} 

def eclipseSourceFolders=[
    'src/main/java',
    'src/main/resources',
    'src/test/java',
    'src/test/resources'
];

tasks.eclipse.dependsOn << {

    for (String sourceFolder: eclipseSourceFolders){ 
        def resourceDir = new File(project.projectDir, sourceFolder)
        if( !resourceDir.exists() && ! resourceDir.mkdirs() ) {
            logger.info("Not able to create %1",resourceDir);
        }
    }
}
/**
Add Following scripts to placs pom.xml within jar and .pom file within libs folder*/

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

/** While creating jar generate and place pom.xml also place .pom file in libs folder */
jar {
    into("META-INF/maven/$project.group/$project.name") {
        from { generatePomFileForMavenJavaPublication }
        rename ".*", "pom.xml"
    }

    doLast {
        pom {
            project {

            }
        }.writeTo("$buildDir/libs/$project.name-${version}.pom")
    }
}