Skip to content

Commit 494979f

Browse files
committed
Add JVM fork options to Asciidoctor Convention Plugin.
1 parent 9b648ad commit 494979f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

buildSrc/src/main/java/io/spring/gradle/convention/AsciidoctorConventionPlugin.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import org.asciidoctor.gradle.jvm.AsciidoctorJExtension;
2929
import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
3030
import org.asciidoctor.gradle.jvm.AsciidoctorTask;
31+
import org.gradle.api.JavaVersion;
3132
import org.gradle.api.Plugin;
3233
import org.gradle.api.Project;
3334
import org.gradle.api.artifacts.Configuration;
34-
import org.gradle.api.artifacts.dsl.RepositoryHandler;
3535
import org.gradle.api.file.DuplicatesStrategy;
3636
import org.gradle.api.file.FileTree;
3737
import org.gradle.api.tasks.Sync;
@@ -87,16 +87,17 @@ public void apply(Project project) {
8787

8888
project.getPlugins().withType(AsciidoctorJPlugin.class, asciidoctorPlugin -> {
8989

90-
createDefaultAsciidoctorRepository(project);
90+
configureMavenCentralRepositoryForAsciidoctor(project);
9191
makeAllWarningsFatal(project);
9292

93-
Sync unzipResources = createUnzipDocumentationResourcesTask(project);
93+
Sync unzipResources = createSyncDocumentationResourcesTask(project);
9494

9595
project.getTasks().withType(AbstractAsciidoctorTask.class, asciidoctorTask -> {
9696

9797
asciidoctorTask.dependsOn(unzipResources);
9898
configureAttributes(project, asciidoctorTask);
9999
configureExtensions(project, asciidoctorTask);
100+
configureForkOptions(asciidoctorTask);
100101
configureOptions(asciidoctorTask);
101102
asciidoctorTask.baseDirFollowsSourceDir();
102103
asciidoctorTask.useIntermediateWorkDir();
@@ -119,14 +120,8 @@ public void apply(Project project) {
119120
});
120121
}
121122

122-
private void createDefaultAsciidoctorRepository(Project project) {
123-
124-
project.getGradle().afterProject(it -> {
125-
126-
RepositoryHandler repositories = it.getRepositories();
127-
128-
repositories.mavenCentral();
129-
});
123+
private void configureMavenCentralRepositoryForAsciidoctor(Project project) {
124+
project.getGradle().afterProject(it -> it.getRepositories().mavenCentral());
130125
}
131126

132127
/**
@@ -141,7 +136,7 @@ private void createDefaultAsciidoctorRepository(Project project) {
141136
* @see org.gradle.api.Project
142137
*/
143138
@SuppressWarnings("all")
144-
private Sync createUnzipDocumentationResourcesTask(Project project) {
139+
private Sync createSyncDocumentationResourcesTask(Project project) {
145140

146141
Configuration documentationResources = project.getConfigurations().maybeCreate("documentationResources");
147142

@@ -175,10 +170,10 @@ private void configureAttributes(Project project, AbstractAsciidoctorTask asciid
175170
Map<String, Object> attributes = new HashMap<>();
176171

177172
attributes.put("attribute-missing", "warn");
173+
attributes.put("docinfo", "shared");
178174
attributes.put("icons", "font");
179175
attributes.put("idprefix", "");
180176
attributes.put("idseparator", "-");
181-
attributes.put("docinfo", "shared");
182177
attributes.put("sectanchors", "");
183178
attributes.put("sectnums", "");
184179
attributes.put("today-year", LocalDate.now().getYear());
@@ -196,6 +191,15 @@ private void configureExtensions(Project project, AbstractAsciidoctorTask asciid
196191
asciidoctorTask.configurations(extensionsConfiguration);
197192
}
198193

194+
private void configureForkOptions(AbstractAsciidoctorTask asciidoctorTask) {
195+
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
196+
asciidoctorTask.forkOptions(options -> options.jvmArgs(
197+
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED",
198+
"--add-opens", "java.base/java.io=ALL-UNNAMED")
199+
);
200+
}
201+
}
202+
199203
private void configureHtmlOnlyAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) {
200204

201205
Map<String, Object> attributes = new HashMap<>();
@@ -205,7 +209,6 @@ private void configureHtmlOnlyAttributes(Project project, AbstractAsciidoctorTas
205209
attributes.put("highlightjs-theme", "github");
206210
attributes.put("linkcss", true);
207211
attributes.put("icons", "font");
208-
attributes.put("stylesheet", "css/spring.css");
209212

210213
asciidoctorTask.getAttributeProviders().add(() -> {
211214

0 commit comments

Comments
 (0)