Skip to content

ShadowJar plugin expects certain Zip files #14

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

Open
manticore-projects opened this issue Feb 28, 2025 · 2 comments
Open

ShadowJar plugin expects certain Zip files #14

manticore-projects opened this issue Feb 28, 2025 · 2 comments
Assignees

Comments

@manticore-projects
Copy link

Greetings.

Unfortunately I am facing a challenge when using your Gradle Plugin together with the ShadowJar plugin.
Please see https://github.com/manticore-projects/xml-doclet and especially https://github.com/manticore-projects/xml-doclet/blob/3bf909031b13540f0cfea26a61395ea56d5d006a/build.gradle#L221

ShadowJar will expect 2 zip files to be created:

  • build/classes/java/xsd2java
  • build/resources/xsd2java

Without those 2 files, it will throw an error message:

Execution failed for task ':shadowJar'.
> Cannot expand ZIP '/home/are/Documents/src/xml-doclet/build/classes/java/xsd2java' as it does not exist.

I do believe, that your Plugin somehow adds those 2 files to the SourceSet or Layout. But I did not see any way to exclude or suppress it.

The only extremely ugly mitigation I found was to create those 2 Zip files:

task createEmptyZip(type: Zip) {
    dependsOn(compileJava)
    destinationDirectory = file('build/classes/java')
    archiveFileName = 'xsd2java'
    // Use 'from' to add files to the zip
    from files('build/classes/java/main/com/manticore/tools/xmldoclet/xjc') {
        include '**/*'  // Includes all files in the directory
    }
}

task createEmptyZip1(type: Zip) {
    dependsOn(processResources)
    destinationDirectory = file('build/resources')
    archiveFileName = 'xsd2java'
    from files('build/resources/main/xjc') {
        include '**/*'  // Includes all files in the directory
    }
}

shadowJar {
    dependsOn(createEmptyZip)
    dependsOn(createEmptyZip1)
    // create the expected ZIP files since we did not find a way to suppress those
    archiveBaseName = 'xml-doclet'
}

This works but completely messes up the task dependencies and also it pollutes the ShadowJar.
Can you please shed some light on why those two files are added and how to mitigate/solve this challenge better?

Thank you so much already!

@lreimer
Copy link
Contributor

lreimer commented Mar 10, 2025

Hey there, this looks like a quite special issue.

Yes, the plugin does add an additional source directory for the generated source files to the project.
This is, so that the Java compiler plugin picks up and compiles these sources.
So the directories you mention are probably a result of this.

  • build/classes/java/xsd2java
  • build/resources/xsd2java

I do not know the ShadowJar plugin nor how it works and what this plugin expects.
For me, it looks more like the ShadowJar plugin should be enabled to work with additional source and build artifact directories.

I don't think it would be smart to include a special handling of this setup into the xsd2java plugin.

Do you have an alternative solution to this problem?

@manticore-projects
Copy link
Author

manticore-projects commented Mar 10, 2025

Greetings! Thank you for responding to my issue.

Yes, the plugin does add an additional source directory for the generated source files to the project.
This is, so that the Java compiler plugin picks up and compiles these sources.

It would help a lot already, what exactly the plugin adds to the Layout and also to have a control over it. Because, it does not seem to correlate with the outputDir dir:

xsd2java {
    // JAXB XJC: JAXB Binding Compiler
    // https://github.com/qaware/xsd2java-gradle-plugin
    schemas {
        javadoc {
            packageName = 'com.manticore.tools.xmldoclet.xjc'
            schemaDirPath = file('src/main/resources/xjc').toPath()
        }
    }

    extension = true
    arguments ['-verbose']
    outputDir = layout.buildDirectory.dir("generated/sources/java/main").get().asFile
}

For me, it looks more like the ShadowJar plugin should be enabled to work with additional source and build artifact directories.

I am not sure about this because, it expects build artifact directories which are just not there.
And those come from xsd2java and do not correlate with outputDir. In my understanding it would be sufficient to not add those build artifact directories to the Gradle layout (implicitly and without control over it) -- or at least to build them when adding to the layout.

The current workaround is to fake those build artifact directories (which is ugly as night).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants