3
  1. 1.私のプロジェクトには、gradleを使用して各メインクラスのjarを構築したい2つのメインクラスがあります。私のソースには 2 つのファイル ValidationRule.java SupportValidator.java があり、両方のファイルにそれぞれ 1 つのメイン クラスがあります 各メイン クラスの jar を構築したい Eclipse から同じことを正常に動作させることができます 2. プロジェクトのソース ファイルをロードしたい2つの異なるフォルダーから、一部が1つのフォルダーにあり、残りが別のフォルダーにあります。つまり、プロジェクト/ 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

わかりました、まず第一に、sourceオンSourceDirectorySetは別のものを取りますSourceDirectorySet。ただし、このsrcDirsメソッドはパスを取ります。そのブロックを次のように変更します。

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

また、次のように2番目のjarタスクを簡単に追加できます。

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

assemble.dependsOn(secondJar)

これにより、と呼ばれる新しいJarタスクが登録されsecondJar、プロジェクトがアセンブルされるときに、このjarも作成されるようになります。

于 2012-12-06T13:32:34.703 に答える