[GRADLE-1269] Project applying War plugin can no longer be used as project lib dependency Created: 22/Dec/10  Updated: 04/Jan/13  Resolved: 16/Oct/11

Status: Resolved
Project: Gradle
Affects Version/s: 0.9
Fix Version/s: 1.0-milestone-5

Type: Bug
Reporter: Peter Niederwieser Assignee: Adam Murdoch
Resolution: Fixed Votes: 4

Issue Links:
Duplicate
Duplicates GRADLE-687 Project dependency on a war project i... Resolved

 Description   

As soon as the War plugin is applied to a project, that project can no longer be used as a project lib dependency, even if jar.enabled is set to true. It seems as if the project's classes were no longer added to the dependent's compile class path.



 Comments   
Comment by Daniel Bartl [ 16/May/11 ]

Following is the description of the possible workaround that solved the problem for me at the moment

  • taken from the mailing list, provided by Adam Murdoch:

"A work around is to enable the 'jar' task, and add it back to the 'archives' configuration:

jar.enabled = true
artifacts

{ archives jar }

It's not a perfect work around, in that you end up with both the jar and war in the compile and runtime classpath, which can be a problem if you then bundle some kind of distribution, or another war, in a dependent project."

Comment by Scott Yancey [ 22/Jun/11 ]

Is there any plan to address this completely? Meaning, a way to include the project simply in jar format only, without also pulling in the war?

Comment by Spencer Allain [ 05/Jul/11 ]

This is duplicated in gradle-687, but there might be different watchers.

While not particularly pretty, and uses an internal api, this gets rid of the war file from the archives (and the classpath), so that normal dependencies work.

import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact;

Configuration archivesConfig = project.getConfigurations().getByName("archives")
Task warTask = project.getTasks().getByName("war")
for (PublishArtifact publishArtifact : archivesConfig.getAllArtifacts()) {
  if (publishArtifact instanceof ArchivePublishArtifact) {
    ArchivePublishArtifact archivePublishArtifact =
      (ArchivePublishArtifact)publishArtifact;
    if (archivePublishArtifact.getArchiveTask() == warTask) {
      archivesConfig.removeArtifact(publishArtifact);
    }
  }
}

You can also check the mailing list, where I describe this pattern, plus some additions that allow for easily wiring up multiple wars to one or more ears.

http://markmail.org/message/retujvgi7jjmza73

-Spencer

Generated at Wed Jun 30 11:51:14 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.