Depending upon how much the upcoming ear plugin borrows from the existing war 
plugin it may or may not suit your needs.

Below is a pattern that we've used here with some success for creating ears for 
multiple application servers (as different things need to be excluded).

Consider projects A, B, and C where A depends upon B and C, yet A produces a 
jar, wars and some ears.  B and C both produce jars and wars.   So A {jar, 
wars, ears}, B {jar, wars}, C {jar, wars} and for dependencies A dependsOn B 
and C, B depends upon C for jars.  A depends upon B and C (and self A) wars to 
bundle into larger scoped ear.

There are obviously many different ways to go about this, such as creating 
completely separate projects for each artifact, but that was not particularly 
appealing for us.

C/B_build.gradle
apply plugin: 'war'

// Now undo much of what the war plugin auto-wires
jar.enabled = true

configurations {
  wars
}

artifacts {
  archives jar
  wars war
}

// Make sure war is no longer part of default artifacts
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);
    }
  }
}

A_gradle.build
// Pretty much the same as the build.gradle's for A and B, but additional 
configuration for ears

configurations {
  ears
}

dependencies {
  ears project(path: ':B', configuration: 'wars')
  ears project(path: ':C', configuration: 'wars')
}

task ear(type: Jar) {
  extension = 'ear'

  metaInf { from 'whatever/path/to/ear/META-INF' }

  from configurations.ears
  from war.outputs.files
}

This is very simplified, as we actually generate wars and ears for multiple 
application servers and create additional "providedRuntime"-like configurations 
for collecting things that need to be removed for specific application servers 
as some are finicky.

We're hoping that the restructuring of how artifacts are maintained and 
published (and presumably dependency declaration) will make it so that rather 
than have things get assigned to the default configuration/archives artifact, 
that convention-based named variants get used instead.

-Spencer

--- On Fri, 5/20/11, Jefferson Magno Solfarello <[email protected]> wrote:

From: Jefferson Magno Solfarello <[email protected]>
Subject: [gradle-user] EAR plugin or sample?
To: [email protected]
Date: Friday, May 20, 2011, 1:04 PM

Hello,

is there an EAR plugin?

If not, does anyone have a sample?

Thanks a lot,

Jefferson

Reply via email to