Skip to content

Commit fbb56e4

Browse files
authored
Merge pull request #7 from koppor/add-modularity-support
Add support for modularity
2 parents 30847dc + 987afd2 commit fbb56e4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

README.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ See this upstream Gradle issue about potentially providing a solution to this pr
3333
Gradle core: https://github.com/gradle/gradle/issues/1989. Hopefully an upstream solution to
3434
this will eliminate the need for this plugin.
3535

36+
== Notes on Modularity
37+
38+
This plugin tries to detect if the current project is modularized.
39+
If it is, the `module-path` is adapted instead of the class path.
40+
Since the classpath variable of gradle is cleared after the patch, plugins relying on it stop working.
41+
As a consequence, this plugin cannot be used together with https://github.com/java9-modularity/gradle-modules-plugin[org.javamodularity.moduleplugin].
42+
3643
== Version Compatibility
3744

3845
* Gradle 8.8+ (may work on earlier versions, but untested)

src/main/kotlin/com/redock/classpathtofile/listener/AbstractClasspathToFileActionListener.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ abstract class AbstractClasspathToFileActionListener: TaskActionListener {
2626
fun classpathToFile(
2727
task: Task,
2828
jvmArgumentProviders: MutableList<CommandLineArgumentProvider>,
29-
classpath: FileCollection
29+
classpath: FileCollection,
30+
isModule: Boolean
3031
) {
3132

3233
cpArgFile = File.createTempFile("classpath-${task.project.name.replace(" ", "_")}", null)
@@ -39,7 +40,12 @@ abstract class AbstractClasspathToFileActionListener: TaskActionListener {
3940
// TODO this doesn't currently handle wildcards, we should expand wildcards before writing to the arg file
4041
// see https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-4856361B-8BFD-4964-AE84-121F5F6CF111
4142
OutputStreamWriter(FileOutputStream(cpArgFile), Charsets.UTF_8).use {
42-
it.write("-cp \"\\")
43+
if (isModule) {
44+
it.write("--module-path")
45+
} else {
46+
it.write("-cp")
47+
}
48+
it.write(" \"\\")
4349
it.write(LINE_SEP)
4450
classpath.files.forEachIndexed { i, file ->
4551
if(i > 0) {

src/main/kotlin/com/redock/classpathtofile/listener/JavaExecSpecActionListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class JavaExecSpecActionListener(private val extension: ClasspathToFilePluginExt
1414
return
1515
}
1616

17-
classpathToFile(task, task.jvmArgumentProviders, task.classpath)
17+
classpathToFile(task, task.jvmArgumentProviders, task.classpath, task.mainModule.isPresent)
1818
task.classpath = EmptyFileCollection
1919
}
2020
}

src/main/kotlin/com/redock/classpathtofile/listener/TestActionListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestActionListener(private val extension: ClasspathToFilePluginExtension):
1515
return
1616
}
1717

18-
classpathToFile(task, task.jvmArgumentProviders, task.classpath)
18+
classpathToFile(task, task.jvmArgumentProviders, task.classpath, false)
1919
task.classpath = EmptyFileCollection
2020
}
2121
}

0 commit comments

Comments
 (0)