Created
March 24, 2023 19:54
-
-
Save Tarmean/9e4f8a32cf56a4e7d78c233dd9a5cdab to your computer and use it in GitHub Desktop.
Gradle task to dump classpath. Useful to launch external tools such as jshell. Using a gradle task/plugin to launch said tools breaks some key inputs such as tab completion because gradle forces its own input handling on top.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task writeClasspath { | |
doLast { | |
Set pathSet = [] | |
project.tasks.withType(JavaExec) { | |
pathSet.addAll(classpath.findAll { it.exists() }) | |
} | |
project.subprojects.each { | |
it.tasks.withType(JavaExec) { | |
pathSet.addAll(classpath.findAll { it.exists() }) | |
} | |
} | |
// if (pathSet.isEmpty()) { | |
// List<String> classesPaths = project.sourceSets.main.output.getClassesDirs().collect { it.getPath() } | |
// jshellTask.logger.info(':jshell could not find the classpath, adding ' + | |
// 'the following paths from project sourceSets: {}', classesPaths) | |
// pathSet.addAll(classesPaths) | |
// List<String> depsPaths = project.configurations.compileClasspath.collect { it.getPath() } | |
// depsPaths.addAll(project.configurations.runtimeClasspath.collect { it.getPath() }) | |
// jshellTask.logger.info(":jshell could not find the dependencies' classpath, adding " + | |
// 'the following paths from project configurations: {}', depsPaths) | |
// pathSet.addAll(depsPaths) | |
// } | |
// Exclude non-directory / non-jar files that jshell doesn't deal with | |
pathSet = pathSet.findAll{ new File(it.toString()).isDirectory() || it.toString().endsWith('.jar') } | |
def path = pathSet.join(System.getProperty("path.separator")) | |
buildDir.mkdirs() | |
new File(buildDir, "classpath.txt").text = path + "\n" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment