-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The module descriptor does not see "packages" from resources, when using 'run' task #22
Comments
Workaround: Create a |
The reason why it fails is that Gradle keeps resources separately from the compiled classes in the I'll keep the issue open, and for now, I will document it as a known limitation with the description of the workaround you have found. |
You don't like either of my two suggested solutions? |
I'm not 100% sure, but I see some potential technical issues:
Generally, I'm a bit afraid of changing too much internal logic of certain plugins :), and I need to take a closer look why application plugin works in this way. If you have some free time, you can also check your concept (I would prefer the solution number #2). |
You can add task dependencies at any time, so not problem with 1. Doing Regarding 2. I already told you what the reason is. The incremental build feature aka up-to-date checks. Gradle checksums the inputs and outputs before and the outputs after the task is run. If the inputs or outputs change between two runs, the task is executed again. If the task inputs are the same as the task inputs before the last run and the task outputs are the same as the task outputs after the last run, the task is considered up-to-date. If two tasks write files to the same directory, it is much harder to determine which output file belongs to which task and also files that were added spuriously and thus can be considered a modification of outputs if the output is the directory, not the individual files, would not be detectable. Thus it is much cleaner and easier to clearly separate the outputs of various tasks. For executing a There should be absolutely no problem to either use the built JAR, or to copy the two output directories into the tasks temporary directory after deleting its contents and adding that to the module path instead of the individual directories. Another option that I used for a different project where the execution of the tool depended on additional files that were put to the distribution, but were of course not present like that to the default task run(type: JavaExec, dependsOn: installDist, overwrite: true) {
description 'Runs this project as a JVM application'
group 'application'
main mainClassName
classpath fileTree("$installDist.destinationDir/lib")
} In a plugin this has to be adapted to get modifications the using build did to the |
Actually,
I think I will ask Gradle developers for an advice, what the best option to implement that would be. In addition, they will fail into the same issue during their implementation of native Gradle support for Jigsaw, so it is even more important to let them know and find a common solution. |
I never said run {
doFirst {
def args = jvmArgs
def modulePathIndex = args.indexOf('--module-path') + 1
def ps = Pattern.quote(System.properties.'path.separator')
def jd = Pattern.quote(file("$buildDir/classes/java/main") as String)
def rd = Pattern.quote(file("$buildDir/resources/main") as String)
args[modulePathIndex] = args[modulePathIndex]
.replaceFirst(/(?:$ps|^)$rd/, '')
.replaceFirst(/(?:$ps|^)$jd/, Matcher.quoteReplacement(temporaryDir as String))
jvmArgs = args
project.sync {
from compileJava
from processResources
into temporaryDir
}
}
} This code works and must be done in Btw. while looking into this I observed private String stripResources(String classpath, File resourceOutputDir) {
String outPath = ":" + resourceOutputDir.getAbsolutePath();
if (classpath.contains(outPath)) {
return classpath.replace(outPath, "");
}
return classpath;
} This cannot work correctly, as |
Source Files:
root-project/application-project/src/main/java/my/package/with/Classes.java
root-project/application-project/src/main/java/module-info.java
root-project/application-project/src/main/resources/images/logo.png
Result Files:
root-project/application-project/build/classes/java/main/my/package/with/Classes.java
root-project/application-project/build/classes/java/main/module-info.class
root-project/application-project/build/resources/main/images/logo.png
Inside module-info.java (central framework class resolves and loads images):
opens images
When this is packaged as a JAR it works fine, as the
images
package then is present at runtime.If there would be an
images
folder with ajava
file inroot-project/application-project/src/main/java/
this would also work fine, as you patch the module with the resources folder.But unfortunately the
module-info.class
seems to be evaluated before the--patch-module
flag is effective and thus fails as there is noimages
package at that point.Due to that, execution fails with
java.lang.module.InvalidModuleDescriptorException: Package images not found in module
as it indeed is not in there in this situation.I guess you should either
--patch-module
flag by adding the built artifact to the module path instead, orroot-project/application-project/classes/java/main/images/
, but you shouldn't do that generally as it makes thecompileJava
task out-of-date to do this, so you would need to sync the dir to some other place (e. g. the temporary directory for the run task) and then add the files, but then you can also simply copy both folders to that place.The text was updated successfully, but these errors were encountered: