Skip to content

Commit 32421cb

Browse files
committed
issue #199: Build failure when using with Gradle 7.2 and Application plugin
1 parent eb4bbf0 commit 32421cb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/main/java/org/javamodularity/moduleplugin/tasks/StartScriptsMutator.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@
88
import org.gradle.api.distribution.DistributionContainer;
99
import org.gradle.api.file.FileCopyDetails;
1010
import org.gradle.api.file.RelativePath;
11+
import org.gradle.api.logging.Logger;
12+
import org.gradle.api.logging.Logging;
1113
import org.gradle.api.tasks.JavaExec;
1214
import org.gradle.api.tasks.application.CreateStartScripts;
1315
import org.javamodularity.moduleplugin.extensions.RunModuleOptions;
1416
import org.javamodularity.moduleplugin.internal.TaskOption;
1517

1618
import java.io.IOException;
19+
import java.nio.charset.Charset;
1720
import java.nio.file.Files;
1821
import java.nio.file.Path;
1922
import java.util.ArrayList;
2023
import java.util.List;
2124

2225
public class StartScriptsMutator extends AbstractExecutionMutator {
26+
private static final Logger LOGGER = Logging.getLogger(StartScriptsMutator.class);
2327

2428
private static final String LIBS_PLACEHOLDER = "APP_HOME_LIBS_PLACEHOLDER";
2529
private static final String PATCH_LIBS_PLACEHOLDER = "APP_HOME_PATCH_LIBS_PLACEHOLDER";
@@ -127,13 +131,27 @@ private void removeClasspathArgs(CreateStartScripts startScriptsTask) {
127131

128132
private static void replaceLibsPlaceHolder(Path path, String libText, String patchLibText) {
129133
try {
130-
String updatedScriptContent = Files.readString(path)
134+
String content = getContent(path);
135+
String updatedScriptContent = content
131136
.replaceAll(LIBS_PLACEHOLDER, libText)
132137
.replaceAll(PATCH_LIBS_PLACEHOLDER, patchLibText);
133138

134139
Files.writeString(path, updatedScriptContent);
135140
} catch (IOException e) {
136-
throw new GradleException("Couldn't replace placeholder in " + path);
141+
throw new GradleException("Couldn't replace placeholder in " + path, e);
142+
}
143+
}
144+
145+
private static String getContent(Path path) {
146+
try {
147+
return Files.readString(path);
148+
} catch (IOException e) {
149+
try {
150+
Charset cs = Charset.forName(System.getProperty("file.encoding"));
151+
return Files.readString(path, cs);
152+
} catch (Exception ex) {
153+
throw new GradleException("Cannot read the content of " + path, ex);
154+
}
137155
}
138156
}
139157

0 commit comments

Comments
 (0)