0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gradle設定メモ (マルチプロジェクト to all in one) 自分用

Last updated at Posted at 2019-06-06

Gradle 5.4.1

tree.
├─sub
│  ├─sub-sample1
│  │  └─src
│  │      ├─main
│  │      │  ├─java
│  │      │  │  └─sample
│  │      │  │      └─subs
│  │      │  │              Sub1.java
│  │      │  │
│  │      │  └─resources
│  │      │       └─subs
│  │      │               subSample1.txt
│  │      └─test
│  │          ├─java
│  │          └─resources
│  └─sub-sample1
│      └─src
│          ├─main
│          │  ├─java
│          │  │  └─sample
│          │  │      └─subs
│          │  │              Sub2.java
│          │  │
│          │  └─resources
│          │      └─subs
│          │              subSample2.txt
│          │
│          └─test
│              ├─java
│              └─resources
└─src
    ├─main
    │  ├─java
    │  │      Main.java
    │  │
    │  └─resources
    │          sample.txt
    │
    └─test
        ├─java
        └─resources
build.gradle
allprojects {
    apply plugin: 'java'
    group 'sample'
    version '1.0-SNAPSHOT'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    compileJava.options.encoding = 'UTF-8'
    repositories { mavenCentral() }
    dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' }
}

dependencies { 
    compile project(':sub:sub-sample1')
    compile project(':sub:sub-sample2')
}

def mainProjects = [':sub:sub-sample1', ':sub:sub-sample2']
task allInJar(type:Jar, dependsOn: mainProjects.collect({ it+':compileJava' })){
    dependsOn build
    baseName = rootProject.name
    manifest.attributes 'Main-Class': 'Main'
    def javaSubDir = "/classes/java/main"
    def resourcesSubDir = "/resources/main"
    from(buildDir.path + javaSubDir,
            files(mainProjects.collect{ project(it).buildDir.path + javaSubDir }))
    from(buildDir.path + resourcesSubDir,
            files(mainProjects.collect{ project(it).buildDir.path + resourcesSubDir }))
}

gradlew allInJarで実行.
task:build << allInJar

jar.
│  Main.class
│  sample.txt
│
├─subs
│      sample1.txt
│      sample2.txt
│
├─META-INF
│      MANIFEST.MF
│
└─sample
    └─subs
            Sub1.class
            Sub2.class

参考;
 Gradle徹底入門 次世代ビルドツールによる自動化基盤の構築(著 綿引 琢磨, 須江 信洋, 林 政利, 今井 勝信)
 java – 複数のプロジェクトを1つのjarファイルにGradleできますか? 

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?