Managing dependencies between war tasks and separate project that generates zipFile with web assets (IntelliJ logging warnings)

Hello everybody,

We are working on a fairly big project (60+ modules or so) and we are creating multiple web applications that share a fair amount of static assets.

So we took the route to have a “WebContent” project that exposes multiple zip artifacts each defined with it’s own zipTask.

// WebContent.gradle
task assetsZip(type: Zip) { 
    classifier "assets"
    ...
}
task assetSourcesZip(type: Zip) { 
    classifier "assets-src"
    ...
}

Then we have various other project in which the war task refers to this zip:

// someWebapplication.gradle
war {
    dependsOn ":WebContent:assetsZip"
    ...
    from(zipTree(project(":WebContent").tasks["assetsZip"].archivePath))
    ...
}

This obviously is some sort of incorrect because I think the from part of the war task is used to determine uptodate-ness and determine if the war task needs to be run. However the zip artifacts will not be there obviously, because they are created by the task mentioned in the dependsOn.

IntelliJ agrees and for each type of dependencies like this, IntelliJ logs an exception when refreshing or importing the project:

Warning:project ‘:someWebApplication’: Web Facets/Artifacts will not be configured properly
Details: org.gradle.api.InvalidUserDataException: Cannot expand ZIP ‘/path/to/WebContent/.build/distributions/WebContent-assets.zip’ as it does not exist.

We are migrating from ant to gradle and there are a few more these types of warnings while we do so. And having these warnings will clutter the logs for more important things we might need to look at.

My question now is, if there is a way to prevent this type of warnings. Are we using the wrong pattern to add static assets to multiple web applications and manage their dependencies? Or is this just a quirk we can safely ignore?

This seems to work better when we use configurations and expose artifacts.

So WebContent project now defines:

configurations { 
   assetsZip
}

task createAssetsZip(type:Zip} { .... }

artifacts {
  assetsZip createAssetsZip
}

Then in someWebapplication.gradle we use

configurations {
   webContent project(path:":WebContent", configuration: "assetsZip")
}

war {
  dependsOn configurations.assetsZip
  from { zipTree(configurations.assetsZip.singleFile)}
}

It works better, but now we have an issue with a lot of .build/tmp/expandedArchives being created. But that is a whole other beast to solve