Skip to content

Commit 81b2732

Browse files
authored
Merge pull request #777 from kusumotolab/revert-shadowjar-usage
fatjar生成方法を元に戻した
2 parents f45824e + 59fe86d commit 81b2732

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
- ~/.gradle
7373
key: v1-dependencies-{{ checksum "build.gradle" }}
7474
# ===== Assemble jar file
75-
- run: ./gradlew shadowJar
75+
- run: ./gradlew assemble
7676
# ===== Collect and persist the built artifacts
7777
- run:
7878
name: Collect artifacts to be released

.circleci/publish-new-release.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ go get -u github.com/tcnksm/ghr
1818

1919
echo "Starting to publish a new release as the version: ${WANTED_VERSION} ..."
2020

21-
# trim suffix "-all" of fat jar
22-
jar=$(ls ./workspace/artifacts/*.jar)
23-
mv $jar ${jar/-all/}
21+
# # trim suffix "-all" of fat jar
22+
# jar=$(ls ./workspace/artifacts/*.jar)
23+
# mv $jar ${jar/-all/}
2424

2525
# generate change log
2626
CHANGELOG="## Change Log

build.gradle

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ plugins {
2121

2222
// Gradle lint
2323
id "nebula.lint" version "16.9.0"
24-
25-
// To generate fat jar
26-
id "com.github.johnrengelman.shadow" version "6.0.0"
2724
}
2825

2926
// Set compiler version
@@ -88,12 +85,20 @@ jar {
8885
attributes "Main-Class": "jp.kusumotolab.kgenprog.CUILauncher"
8986
}
9087

88+
// fatjar must include all dependencies
89+
from {
90+
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
91+
}
92+
// exclude jar signatures for jar compression to avoid invalid signature
93+
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
94+
9195
doFirst {
9296
// copy gradle.properties to resolve version info
9397
copy {
9498
from 'gradle.properties'
9599
into buildDir.name + '/resources/main/'
96100
}
101+
97102
// annotate whether this task was executed on CI or not
98103
def isCi = System.getenv('CI') ? 'true' : 'false'
99104
File prop = new File(buildDir.name + '/resources/main/gradle.properties')
@@ -123,8 +128,3 @@ jacocoTestReport {
123128
}))
124129
}
125130
}
126-
127-
// Minimize generating fat jar
128-
shadowJar {
129-
minimize()
130-
}

src/main/java/jp/kusumotolab/kgenprog/project/factory/JUnitLibraryResolver.java

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package jp.kusumotolab.kgenprog.project.factory;
22

3+
import java.io.IOException;
34
import java.io.InputStream;
45
import java.nio.file.Files;
56
import java.nio.file.Path;
67
import java.nio.file.StandardCopyOption;
7-
import java.util.Arrays;
8+
import java.util.Collections;
89
import java.util.EnumMap;
910
import java.util.List;
11+
import java.util.MissingResourceException;
1012
import jp.kusumotolab.kgenprog.CUILauncher;
1113
import jp.kusumotolab.kgenprog.project.ClassPath;
1214

@@ -25,26 +27,26 @@ public enum JUnitVersion {
2527
new EnumMap<>(JUnitVersion.class);
2628

2729
static {
30+
setupResourceJar(JUNIT3_DIR, JUNIT3_JUNIT, JUnitVersion.JUNIT3);
31+
setupResourceJar(JUNIT4_DIR, JUNIT4_JUNIT, JUnitVersion.JUNIT4);
32+
}
33+
34+
private static void setupResourceJar(final String dir, final String jar,
35+
final JUnitVersion version) {
36+
final String jarPath = dir + jar;
37+
final ClassLoader classLoader = CUILauncher.class.getClassLoader();
38+
final InputStream is = classLoader.getResourceAsStream(jarPath);
39+
if (null == is) {
40+
throw new MissingResourceException("Missing runtime junit library: " + jarPath, jarPath, "");
41+
}
2842

43+
final Path tempPath = getTempDirectory().resolve(jar);
2944
try {
30-
final ClassLoader classLoader = CUILauncher.class.getClassLoader();
31-
final InputStream junit3JInputStream =
32-
classLoader.getResourceAsStream(JUNIT3_DIR + JUNIT3_JUNIT);
33-
final InputStream junit4JInputStream =
34-
classLoader.getResourceAsStream(JUNIT4_DIR + JUNIT4_JUNIT);
35-
36-
final Path systemTempPath = getTempDirectory();
37-
final Path junit3JPath = systemTempPath.resolve(JUNIT3_JUNIT);
38-
final Path junit4JPath = systemTempPath.resolve(JUNIT4_JUNIT);
39-
40-
Files.copy(junit3JInputStream, junit3JPath, StandardCopyOption.REPLACE_EXISTING);
41-
Files.copy(junit4JInputStream, junit4JPath, StandardCopyOption.REPLACE_EXISTING);
42-
43-
libraries.put(JUnitVersion.JUNIT3, Arrays.asList(new ClassPath(junit3JPath)));
44-
libraries.put(JUnitVersion.JUNIT4, Arrays.asList(new ClassPath(junit4JPath)));
45-
} catch (Exception e) {
46-
e.printStackTrace();
45+
Files.copy(is, tempPath, StandardCopyOption.REPLACE_EXISTING);
46+
} catch (final IOException e) {
47+
throw new RuntimeException(e);
4748
}
49+
libraries.put(version, Collections.singletonList(new ClassPath(tempPath)));
4850
}
4951

5052
// TODO 一時dirの責務をひとまずこのクラスに任せたが,巨大になるなら別クラスに切った方がよさそう.
@@ -55,8 +57,8 @@ public static Path getTempDirectory() {
5557
if (null == tempDir) {
5658
tempDir = Files.createTempDirectory("kgp-");
5759
}
58-
} catch (Exception e) {
59-
e.printStackTrace();
60+
} catch (final IOException e) {
61+
throw new RuntimeException(e);
6062
}
6163
return tempDir;
6264
}

0 commit comments

Comments
 (0)