3
  1. 1.我的项目有两个主类,我想使用 gradle 为每个主类构建 jar。我的源有 2 个文件 ValidationRule.java SupportValidator.java 两个文件都有一个主类,每个我想为每个主类构建 jar 我可以从 eclipse 中实现相同的工作正常 2.我想为我的项目加载源文件来自 2 个不同的文件夹,一部分在一个文件夹中,其余部分在另一个文件夹中,即项目/src snd 项目外部的另一个文件夹(../../../SharedClass)

    我的脚本如下

    apply plugin: 'eclipse'
    apply plugin: 'java'
    
    sourceCompatibility = 1.6
    archivesBaseName = 'Process_XY'
    
    configurations {
        configurations.compile.transitive = false
    }
    
    dependencies {
        compile fileTree(dir:'/trunk/Solutions/project/Source/Binaries/CommonFunctions/build/libs', include: '*.jar')
        compile fileTree(dir:'/trunk/Solutions/project/lib/GeoTools/geotools-2.7.4-bin/geotools-2.7.4', include: '*.jar')
        compile "org.apache.hadoop:hadoop-core:1.0.3"
        compile "commons-collections:commons-collections:3.2.1"
        compile "commons-configuration:commons-configuration:1.6"
        compile "commons-discovery:commons-discovery:0.2"
        compile "commons-lang:commons-lang:2.4"
        compile "commons-logging:commons-logging:1.1.1"
        compile "commons-logging:commons-logging:1.0.4"
        compile "log4j:log4j:1.2.16"
        compile "com.vividsolutions:jts:1.8"
        compile "commons-net:commons-net:1.4.1"
        compile "org.apache.hadoop:hadoop-core:1.0.3"
        compile "commons-httpclient:commons-httpclient:3.0.1"
        compile "org.mortbay.jetty:servlet-api:2.5-20081211"
        compile "org.apache.hbase:hbase:0.94.0"
        compile "org.apache.zookeeper:zookeeper:3.4.3"
    }
    
    repositories {
        mavenCentral()
        maven { url "https://repository.cloudera.com/artifactory/cloudera-repos/" }
        maven { url "http://repo.springsource.org/libs-release" }
        maven { url "http://repo.springsource.org/libs-milestone" }
        maven { url "http://repo.springsource.org/libs-snapshot" }
        maven { url "http://www.datanucleus.org/downloads/maven2/" }
        maven { url "http://oss.sonatype.org/content/repositories/snapshots" }
        maven { url "http://people.apache.org/~rawson/repo" }
    }
    
    jar {
        from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        manifest.attributes("Main-Class":"org.project.seismic.Process_XY")
    }   
    
    sourceSets {
        main {
            java {
                 source = ['src/org', '../../../SharedClass/org']
            }
        }
    }
    

    以上在 sourceSets 方法中,我尝试从 2 个文件夹加载源代码,但没有成功

    提前致谢..!!如何使用gradle实现。

4

1 回答 1

7

好的,首先,sourceon aSourceDirectorySet需要另一个SourceDirectorySet。然而,该srcDirs方法需要路径。将该块更改为以下内容:

sourceSets {
  main {
    java {
      srcDirs ['src/org', '../../../SharedClass/org']
    }
  }
}

您可以轻松添加第二个 jar 任务,如下所示:

task secondJar(type: Jar) {
  name = other-main-jar
  from ...
  manifest.attributes(...)
}

assemble.dependsOn(secondJar)

这将注册一个名为的新 Jar 任务secondJar,并确保在组装项目时也会创建此 jar。

于 2012-12-06T13:32:34.703 回答