使用gradle为每个主类构建jar

时间:2012-12-05 11:56:01

标签: gradle

  1. 1.我的项目有两个主要类我想使用gradle为每个主类构建jar。我的源码有2个文件ValidationRule.java      SupportValidator.java这个文件每个我想要一个主类      为每个主类构建jar      我可以通过eclipse工作得很好      2.我想从2个不同的文件夹加载我的项目的源文件,有些部分在一个文件夹中,剩下的就是 在那里      另一个文件夹,如      project / src和项目外的另一个文件夹(../../../ 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。

1 个答案:

答案 0 :(得分:7)

好的,首先,source上的SourceDirectorySet需要另一个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)

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