概要

インストール

  • Windows + Cygwinの環境でSDKMANからGradleをインストール
  • Cygwin
    • setup-x86_64.exeなどから、curlunzipzipをインストール
  • SDKMAN: Cygwin terminalなどから、以下を実行してインストールし、ターミナルを再起動
    curl -s "https://get.sdkman.io" | bash
  • Gradle:
    sdk install gradle

サンプル

aterai/java-swing-tipsのような、大量(AccordionPanelZoomingAndPanning700ほど)のサブプロジェクトが存在する場合のサンプルです。

  • build.gradle
description 'Java Swing Tips'

//allprojects と subprojects の使い分け方が良く分かっていない...
allprojects {
  apply {
    plugin 'java'
    plugin 'application'
  }

  def defaultEncoding = 'UTF-8'
  [compileJava, compileTestJava]*.options*.encoding = defaultEncoding

  repositories {
    jcenter()
  }
}

subprojects {
  sourceSets {
    main {
      //デフォルトプロジェクトレイアウトでは src/main/java
      java { srcDir 'src/java' }
      //デフォルトプロジェクトレイアウトは src/main/resources
      resources { srcDir 'src/java' }
    }
  }

  def config = new ConfigSlurper().parse(new File("${project.projectDir}/config.gradle").toURL())

  mainClassName = config.main.class

  // In this section you declare where to find the dependencies of your project
  repositories {
    flatDir { dirs "${project.projectDir}/lib" }
  }

  // In this section you declare the dependencies for your production and test code
  dependencies {
    compile fileTree(dir: "${project.projectDir}/lib", include: '*.jar')
  }

  version = config.version
  jar {
    manifest {
      attributes 'Implementation-Version': config.version,
                 'Implementation-Vendor': config.vendor,
                 'Main-Class': config.main.class,
                 'Class-Path': config.runtime.classpath
    }
  }

  apply {
    plugin 'pmd'
    plugin 'checkstyle'
    plugin 'findbugs'
  }
  pmd {
    ignoreFailures = true
    consoleOutput = true
    ruleSetFiles = files("${rootProject.projectDir}/ruleset.xml")
    ruleSets = []
  }
  checkstyleMain {
    ignoreFailures = true
    configFile = file("${rootProject.projectDir}/checkstyle.xml")
  }
  findbugs {
    ignoreFailures = true
    excludeFilter = file("${rootProject.projectDir}/excludefilter.xml")
  }
}
  • settings.gradle
//サブプロジェクトとしてAccordionPanel~ZoomingAndPanningを追加
//700ほど追加すると重い...
file('.').eachDirMatch(~/[a-zA-Z]+/) {
    include it.name
}
  • AccordionPanelZoomingAndPanning以下にconfig.gradle
vendor  = 'Java Swing Tips - https://ateraimemo.com/'
version = '1.0.0'
year    = '2003-2016'

main.class = 'example.MainPanel'
runtime.classpath = '.'

実行方法

  • すべてのサブプロジェクトを実行
$ gradle clean
:clean UP-TO-DATE
:AccordionPanel:clean
:ActionMap:clean
... 中略 ...
:ZoomAndPanPanel:clean UP-TO-DATE
:ZoomingAndPanning:clean UP-TO-DATE

BUILD SUCCESSFUL

Total time: 8.747 secs

Antで同様にcleanタスクを実行すると5秒程度

$ ant -f all.xml -Dall=clean
Buildfile: C:\tmp\jst\all.xml
all:
clean:
clean:
   [delete] Deleting directory C:\tmp\jst\AccordionPanel\target
... 中略 ...
clean:
   [delete] Deleting directory C:\tmp\jst\ZoomingAndPanning\target

BUILD SUCCESSFUL
Total time: 5 seconds
  • サブプロジェクトを指定して実行
$ gradle :ZoomingAndPanning:check
:ZoomingAndPanning:compileJava UP-TO-DATE
:ZoomingAndPanning:processResources UP-TO-DATE
:ZoomingAndPanning:classes UP-TO-DATE
:ZoomingAndPanning:checkstyleMain
:ZoomingAndPanning:compileTestJava UP-TO-DATE
:ZoomingAndPanning:processTestResources UP-TO-DATE
:ZoomingAndPanning:testClasses UP-TO-DATE
:ZoomingAndPanning:checkstyleTest UP-TO-DATE
:ZoomingAndPanning:findbugsMain
:ZoomingAndPanning:findbugsTest UP-TO-DATE
:ZoomingAndPanning:pmdMain
:ZoomingAndPanning:pmdTest UP-TO-DATE
:ZoomingAndPanning:test UP-TO-DATE
:ZoomingAndPanning:check

BUILD SUCCESSFUL

Total time: 17.056 secs

参考リンク

コメント