Gradle

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
To raise new issues or bugs against Gradle, please use forums.gradle.org.
  • Gradle
  • GRADLE-1912

Project Dependency for ear / war not working

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Resolution: Unresolved
  • Affects Version/s: 1.0-milestone-5
  • Fix Version/s: None

Description

Problem:
It is not possible to build an ear with a war using the ear plugin with project dependencies.

Expected behaviour:
The expected bahaviour would be, that the "war" is placed inside the ear, but instead the content of the "war" project is packaged as "jar" and placed into the ear. It seems that the wrong dependent tasks are executed.

Reproduction:

  • Open the Sample project folder "samples\ear\earWithWar" in the gradle distribution
  • execute the command "gradle ear"
  • With milestone 4 the task ":war:war" is executed (correct behaviour)
  • With milestone 5 the task ":war:jar" is executed (incorrect behaviour)

See build output below.

#########################################

  1. ear - milestone 4
    #########################################
    C:\Development\Tools\gradle-1.0-milestone-5\samples\ear\earWithWar>gradle ear
    :war:compileJava
    :war:processResources UP-TO-DATE
    :war:classes
    :war:war
    :ear

BUILD SUCCESSFUL

Total time: 6.937 secs

#########################################

  1. ear - milestone 5
    #########################################
    C:\Development\Tools\gradle-1.0-milestone-5\samples\ear\earWithWar>gradle ear
    :war:compileJava
    Download http://repo1.maven.org/maven2/log4j/log4j/1.2.15/log4j-1.2.15.pom
    > Building > :war:compileJava > Resolve dependencies ':war:compile' > 17 KB/17 K
    Download http://repo1.maven.org/maven2/log4j/log4j/1.2.15/log4j-1.2.15.jar
    :war:processResources UP-TO-DATE
    :war:classes
    :war:jar
    :ear

BUILD SUCCESSFUL

Total time: 10.976 secs

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • TeamCity
  • Commits
  • Source
  • Reviews
Hide
Permalink
Richard Bywater added a comment - 10/Nov/11 7:14 PM - edited

I'm wondering (from a quick glance) whether this might be related to the fix that was made for GRADLE-687 and GRADLE-1269

Show
Richard Bywater added a comment - 10/Nov/11 7:14 PM - edited I'm wondering (from a quick glance) whether this might be related to the fix that was made for GRADLE-687 and GRADLE-1269
Hide
Permalink
Thor Åge Eldby added a comment - 11/Nov/11 4:05 AM

See also http://forums.gradle.org/gradle/topics/problem_with_the_ear_plugin and http://gradle.1045684.n5.nabble.com/Ear-plugin-does-not-include-my-war-files-in-milestone-5-td4980884.html (where I have a small example).

Show
Thor Åge Eldby added a comment - 11/Nov/11 4:05 AM See also http://forums.gradle.org/gradle/topics/problem_with_the_ear_plugin and http://gradle.1045684.n5.nabble.com/Ear-plugin-does-not-include-my-war-files-in-milestone-5-td4980884.html (where I have a small example).
Hide
Permalink
Russ Egan added a comment - 08/Dec/11 1:33 PM

Just hit this. Our solution will probably be to add a "wars" configuration to all projects with the war plugin, and use that for publishing just the war artifact.

But generally, we've run into this issue in many different forms. There is a general...lack of a best practice for selectively depending on particular artifacts of another project. We've needed several times to say "I depend only on the .war artifact of subproject X" or "only on the X-fat.jar" or "the .jar, sources.jar, and javadoc.jar" or "the X-bin.tar, but not the X-source.tar or X-all.tar" etc.

In most cases this comes up in assembly types of projects (like an ear project, or a project used to bundle our product into distribution tars), though we also had a case where we'd developed some re-usable shell scripts and .conf files that were pulled into other projects as dependencies.

I think the appropriate practice is to define publish configurations for each unique subset of files? This is what we've been doing so far. Though it means the publishing project needs to know a priori what subsets of its published artifacts other projects might depend on, which is a little wonky.

I guess the alternative is Maven's approach of 1 project = 1 artifact. Then every single unique artifact has a unique locator/name that other projects can refer to. When gradle projects publish multiple artifacts, those artifacts may or may not have unique names to refer to them. And project() type dependencies don't really make it clear how you would refer to specific artifacts anyway (can't use classifier or artifact keys like you can with module dependencies).

Show
Russ Egan added a comment - 08/Dec/11 1:33 PM Just hit this. Our solution will probably be to add a "wars" configuration to all projects with the war plugin, and use that for publishing just the war artifact. But generally, we've run into this issue in many different forms. There is a general...lack of a best practice for selectively depending on particular artifacts of another project. We've needed several times to say "I depend only on the .war artifact of subproject X" or "only on the X-fat.jar" or "the .jar, sources.jar, and javadoc.jar" or "the X-bin.tar, but not the X-source.tar or X-all.tar" etc. In most cases this comes up in assembly types of projects (like an ear project, or a project used to bundle our product into distribution tars), though we also had a case where we'd developed some re-usable shell scripts and .conf files that were pulled into other projects as dependencies. I think the appropriate practice is to define publish configurations for each unique subset of files? This is what we've been doing so far. Though it means the publishing project needs to know a priori what subsets of its published artifacts other projects might depend on, which is a little wonky. I guess the alternative is Maven's approach of 1 project = 1 artifact. Then every single unique artifact has a unique locator/name that other projects can refer to. When gradle projects publish multiple artifacts, those artifacts may or may not have unique names to refer to them. And project() type dependencies don't really make it clear how you would refer to specific artifacts anyway (can't use classifier or artifact keys like you can with module dependencies).
Hide
Permalink
Andrew Oberstar added a comment - 29/Dec/11 12:57 PM

This behavior seems very wrong. If I have a WAR project, why should my dependency on it imply that I want the JAR instead?

I assume the fix for this would be to add the WAR to the runtime configuration and remove the JAR.

I don't really understand the use case for GRADLE-687 and GRADLE-1269. Can anyone explain that better?

Show
Andrew Oberstar added a comment - 29/Dec/11 12:57 PM This behavior seems very wrong. If I have a WAR project, why should my dependency on it imply that I want the JAR instead? I assume the fix for this would be to add the WAR to the runtime configuration and remove the JAR. I don't really understand the use case for GRADLE-687 and GRADLE-1269. Can anyone explain that better?
Hide
Permalink
Georg Fleischer added a comment - 02/Feb/12 4:26 AM

Could you please fix this issue? We must stick to Milestone 4 as long as this issue is not fixed. And we want to upgrade Gradle as soon as possible.

Show
Georg Fleischer added a comment - 02/Feb/12 4:26 AM Could you please fix this issue? We must stick to Milestone 4 as long as this issue is not fixed. And we want to upgrade Gradle as soon as possible.
Hide
Permalink
Thor Åge Eldby added a comment - 02/Feb/12 5:28 AM

Spencer Allain shows a way around the problem here: http://forums.gradle.org/gradle/topics/problem_with_the_ear_plugin

That said, this is a pretty daft bug, which everyone dealing with wars in ears will encounter.

Show
Thor Åge Eldby added a comment - 02/Feb/12 5:28 AM Spencer Allain shows a way around the problem here: http://forums.gradle.org/gradle/topics/problem_with_the_ear_plugin That said, this is a pretty daft bug, which everyone dealing with wars in ears will encounter.
Hide
Permalink
Georg Fleischer added a comment - 03/Feb/12 7:37 AM - edited

The workaround which Spencer Allain shows in the thread mentioned above is working for me. Thank you for posting this hint.

Workaround by Spencer Allain:

dependencies { deploy project(path: ':war', configuration: 'archives') }

Show
Georg Fleischer added a comment - 03/Feb/12 7:37 AM - edited The workaround which Spencer Allain shows in the thread mentioned above is working for me. Thank you for posting this hint. Workaround by Spencer Allain: dependencies { deploy project(path: ':war', configuration: 'archives') }
Hide
Permalink
Pablo Munoz added a comment - 23/Feb/12 1:13 PM

I also ran into this issue and did this to workaround. Not as pretty.

deploy fileTree(new File(project(':war').buildDir,'libs'))

Show
Pablo Munoz added a comment - 23/Feb/12 1:13 PM I also ran into this issue and did this to workaround. Not as pretty. deploy fileTree(new File(project(':war').buildDir,'libs'))
Hide
Permalink
Mike M. added a comment - 02/Mar/12 8:27 AM - edited

I totally agree with Andrew Oberstar: GRADLE-687 and GRADLE-1269 made things much worse because now you have to take additional steps if you want the most common behavior. This seems very wrong. If someone wanted a jar instead of a war, he could've created a multi-project build with jar and war subprojects.

Here's a working workarount:

In the war project:

// When we user this project's "archives" configuration, we don't want the jar
jar.enabled = false

In the ear project:

dependencies {
    deploy project(path: ':war-project', configuration: 'archives')
}

Whatever you do, you should at least update the documentation at: http://gradle.org/docs/current/userguide/ear_plugin.html#sec:customizing Because that just doesn't work.

Best regards,
Mike

Show
Mike M. added a comment - 02/Mar/12 8:27 AM - edited I totally agree with Andrew Oberstar: GRADLE-687 and GRADLE-1269 made things much worse because now you have to take additional steps if you want the most common behavior. This seems very wrong. If someone wanted a jar instead of a war, he could've created a multi-project build with jar and war subprojects. Here's a working workarount: In the war project:
// When we user this project's "archives" configuration, we don't want the jar
jar.enabled = false
In the ear project:
dependencies {
    deploy project(path: ':war-project', configuration: 'archives')
}
Whatever you do, you should at least update the documentation at: http://gradle.org/docs/current/userguide/ear_plugin.html#sec:customizing Because that just doesn't work. Best regards, Mike

People

  • Assignee:
    Unassigned
    Reporter:
    Georg Fleischer
Vote (15)
Watch (14)

Dates

  • Created:
    10/Nov/11 8:12 AM
    Updated:
    02/Mar/12 8:29 AM
  • Atlassian JIRA (v5.0.3#729-sha1:bf569e4)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Gradle. Try JIRA - bug tracking software for your team.