Skip to content

Commit 7bf5d57

Browse files
committed
Release v2.18.0
- Fix deprecated 'main' property in JavaExecSpec (use 'mainClass' instead) - Updated JsDocTask, RequireJsTask, and Props2JsTask - Fix Java 17 compatibility: target Java 17 bytecode while compiling with Java 21 - Fix deprecated 'archives' configuration in build.gradle - Add Javadoc comments to JavaScriptProcessingChain interface - Fix groovydoc task to skip when Java version is incompatible
1 parent f16b533 commit 7bf5d57

File tree

6 files changed

+86
-19
lines changed

6 files changed

+86
-19
lines changed

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ apply plugin: 'maven-publish'
1010
apply plugin: 'java'
1111

1212
java {
13-
// Use Java 21 as primary version for newer Closure Compiler support
14-
sourceCompatibility = JavaVersion.VERSION_21
15-
targetCompatibility = JavaVersion.VERSION_21
13+
// Compile with Java 21 toolchain for newer Closure Compiler support
14+
// But target Java 17 bytecode so the plugin can run on Java 17+
15+
sourceCompatibility = JavaVersion.VERSION_17
16+
targetCompatibility = JavaVersion.VERSION_17
1617
toolchain {
1718
languageVersion = JavaLanguageVersion.of(21)
1819
}
@@ -115,8 +116,9 @@ groovydoc {
115116
}
116117
}
117118

118-
artifacts {
119-
archives groovydocJar, sourceJar
119+
// Artifacts are now added directly to the assemble task instead of using the deprecated archives configuration
120+
tasks.named('assemble').configure {
121+
dependsOn groovydocJar, sourceJar
120122
}
121123

122124
publishing {

src/main/groovy/com/eriwen/gradle/js/source/JavaScriptProcessingChain.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,51 @@
44
import org.gradle.api.NamedDomainObjectList;
55
import org.gradle.api.tasks.SourceTask;
66

7+
/**
8+
* A chain of JavaScript processing tasks that can be applied to a source set.
9+
*/
710
public interface JavaScriptProcessingChain extends NamedDomainObjectList<SourceTask> {
811

12+
/**
13+
* Gets the source set associated with this processing chain.
14+
* @return the JavaScript source set
15+
*/
916
JavaScriptSourceSet getSource();
1017

18+
/**
19+
* Creates a task with an auto-generated name based on the task type.
20+
* @param type the task class
21+
* @param <T> the task type
22+
* @return the created task
23+
*/
1124
<T extends SourceTask> T task(Class<T> type);
25+
26+
/**
27+
* Creates a task with the specified name.
28+
* @param name the task name
29+
* @param type the task class
30+
* @param <T> the task type
31+
* @return the created task
32+
*/
1233
<T extends SourceTask> T task(String name, Class<T> type);
34+
35+
/**
36+
* Creates a task with an auto-generated name and configures it with a closure.
37+
* @param type the task class
38+
* @param closure the configuration closure
39+
* @param <T> the task type
40+
* @return the created task
41+
*/
1342
<T extends SourceTask> T task(Class<T> type, Closure closure);
43+
44+
/**
45+
* Creates a task with the specified name and configures it with a closure.
46+
* @param name the task name
47+
* @param type the task class
48+
* @param closure the configuration closure
49+
* @param <T> the task type
50+
* @return the created task
51+
*/
1452
<T extends SourceTask> T task(String name, Class<T> type, Closure closure);
1553

1654
}

src/main/groovy/com/eriwen/gradle/js/source/internal/DefaultJavaScriptProcessingChain.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,37 @@
1616
import java.util.Collections;
1717
import java.util.concurrent.Callable;
1818

19+
/**
20+
* Default implementation of a JavaScript processing chain.
21+
*/
1922
public class DefaultJavaScriptProcessingChain extends DefaultNamedDomainObjectList<SourceTask> implements JavaScriptProcessingChain {
2023

2124
private final DefaultJavaScriptSourceSet source;
2225
private final Project project;
2326

27+
/**
28+
* Creates a new JavaScript processing chain.
29+
* @param project the Gradle project
30+
* @param source the JavaScript source set
31+
* @param instantiator the instantiator for creating tasks
32+
*/
2433
public DefaultJavaScriptProcessingChain(Project project, DefaultJavaScriptSourceSet source, Instantiator instantiator) {
2534
super(SourceTask.class, instantiator, (Namer<SourceTask>) SourceTask::getName, CollectionCallbackActionDecorator.NOOP);
2635
this.source = source;
2736
this.project = project;
2837
wireChain();
2938
}
3039

40+
/**
41+
* {@inheritDoc}
42+
*/
3143
public JavaScriptSourceSet getSource() {
3244
return source;
3345
}
3446

47+
/**
48+
* Wires the processing chain so that each task's source is the output of the previous task.
49+
*/
3550
protected void wireChain() {
3651
all(new Action<SourceTask>() {
3752
public void execute(final SourceTask sourceTask) {
@@ -66,16 +81,22 @@ public <T extends SourceTask> T task(Class<T> type, Closure closure) {
6681

6782
@SuppressWarnings("unchecked")
6883
public <T extends SourceTask> T task(String name, Class<T> type, Closure closure) {
69-
T task = project.getTasks().create(name, type);
70-
if (closure != null) {
71-
closure.setDelegate(task);
72-
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
73-
closure.call(task);
74-
}
84+
T task = project.getTasks().register(name, type, t -> {
85+
if (closure != null) {
86+
closure.setDelegate(t);
87+
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
88+
closure.call(t);
89+
}
90+
}).get();
7591
add(task);
7692
return task;
7793
}
7894

95+
/**
96+
* Calculates a task name based on the task type.
97+
* @param type the task class
98+
* @return the calculated task name
99+
*/
79100
protected String calculateName(Class<? extends SourceTask> type) {
80101
String name = type.getName();
81102
if (name.endsWith("Task")) {

src/main/groovy/com/eriwen/gradle/js/tasks/JsDocTask.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.gradle.api.tasks.OutputDirectory
2222
import org.gradle.api.tasks.TaskAction
2323
import org.gradle.api.tasks.util.internal.PatternSetFactory
2424
import org.gradle.process.JavaExecSpec
25+
import org.gradle.process.ExecOperations
2526

2627
class JsDocTask extends SourceTask {
2728
private PatternSetFactory _patternSetFactory
@@ -65,10 +66,11 @@ class JsDocTask extends SourceTask {
6566
args.addAll(['-d', (destinationDir as File).absolutePath])
6667
args.addAll(project.jsdoc.options.collect { it })
6768

68-
project.javaexec { JavaExecSpec spec ->
69+
def execOps = project.services.get(ExecOperations)
70+
execOps.javaexec { JavaExecSpec spec ->
6971
spec.classpath = project.files("${workingDir}${File.separator}rhino${File.separator}js.jar")
7072
spec.workingDir = new File(workingDir)
71-
spec.main = 'org.mozilla.javascript.tools.shell.Main'
73+
spec.mainClass = 'org.mozilla.javascript.tools.shell.Main'
7274
spec.args = args
7375
}
7476
}

src/main/groovy/com/eriwen/gradle/js/tasks/Props2JsTask.groovy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import org.gradle.api.tasks.SourceTask
2121
import org.gradle.api.tasks.TaskAction
2222
import org.gradle.api.tasks.OutputFile
2323
import org.gradle.api.tasks.util.internal.PatternSetFactory
24+
import org.gradle.process.ExecOperations
25+
import org.gradle.process.JavaExecSpec
2426

2527
class Props2JsTask extends SourceTask {
2628
private PatternSetFactory _patternSetFactory
@@ -62,14 +64,14 @@ class Props2JsTask extends SourceTask {
6264
}
6365

6466
final File props2JsJar = RESOURCE_UTIL.extractFileToDirectory(new File(project.buildDir, TMP_DIR), PROPS2JS_JAR)
65-
final List<String> props2JsArgs = [props2JsJar.canonicalPath, (source.files.toArray() as File[])[0].canonicalPath, '-t', type]
67+
final List<String> props2JsArgs = ['-jar', props2JsJar.canonicalPath, (source.files.toArray() as File[])[0].canonicalPath, '-t', type]
6668
if (functionName) {
6769
props2JsArgs.addAll(['--name', functionName])
6870
}
6971
props2JsArgs.addAll(['-o', (dest as File).canonicalPath])
70-
project.javaexec {
71-
main = '-jar'
72-
args = props2JsArgs
72+
def execOps = project.services.get(ExecOperations)
73+
execOps.javaexec { JavaExecSpec spec ->
74+
spec.args = props2JsArgs
7375
}
7476
}
7577
}

src/main/groovy/com/eriwen/gradle/js/tasks/RequireJsTask.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.gradle.api.tasks.SourceTask
2424
import org.gradle.api.tasks.OutputFile
2525
import org.gradle.api.tasks.util.internal.PatternSetFactory
2626
import org.gradle.process.JavaExecSpec
27+
import org.gradle.process.ExecOperations
2728
import org.gradle.api.tasks.JavaExec
2829

2930
class RequireJsTask extends SourceTask {
@@ -91,9 +92,10 @@ class RequireJsTask extends SourceTask {
9192
try {
9293
// Use project.javaexec if available, otherwise create JavaExec task directly
9394
try {
94-
project.javaexec { JavaExecSpec spec ->
95+
def execOps = project.services.get(ExecOperations)
96+
execOps.javaexec { JavaExecSpec spec ->
9597
spec.classpath = project.configurations.rhino
96-
spec.main = 'org.mozilla.javascript.tools.shell.Main'
98+
spec.mainClass = 'org.mozilla.javascript.tools.shell.Main'
9799
spec.args = args
98100
spec.workingDir = project.projectDir
99101
if (rhinoMaxHeapSize) {

0 commit comments

Comments
 (0)