1

I have a war file which have classes which needs to be used in my Java project. How can I add war file as dependency in this Java project? Gradle pick jar file but no war file. Is there a way to add war as dependency.

build.gradle

group 'com.asklytics'
version 'unspecified'

apply plugin: 'java'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
    maven { url "../$localMavenRepoRoot/local-maven-repo" }
}

dependencies {
    compile group: 'com.asklytics', name: 'asklytics-mailer', version: '1.0-SNAPSHOT', changing: true
    testCompile group: 'junit', name: 'junit', version: '4.11'
}
Bilal Shah
  • 1,135
  • 7
  • 17
  • 42

1 Answers1

2

A war structure is different from a jar structure. You can make gradle pick up a file named something.war as a dependency using @war in the dependency identifier, but you'll likely not be able to use the classes that live in the war.

Probably the best way to do this is to make the project that produces the war, also publish a jar file, which you can then use as a dependency.

RaGe
  • 22,696
  • 11
  • 72
  • 104
  • will jar work as same as war file. It is a grails project which will be used as dependency in other non-grails project. – Bilal Shah Apr 04 '16 at 19:17
  • When you use a jar as a dependency, you're just using the class files and resources from it. A war can contain other files which you will not use as a dependency anyway. see: http://stackoverflow.com/questions/5871053/java-war-vs-jar-what-is-the-difference – RaGe Apr 04 '16 at 20:48