Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle: adding jar to web-inf

Tags:

gradle

war

i have created a gradle build and added java, scala, war, jetty code and its all working fine.



apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'war'
apply plugin: 'jetty'

List compileTime = [
                    "javax.servlet:servlet-api:2.4@jar",
                    "org.scalatra:scalatra_2.8.0:2.0.0.M2@jar",
                    "org.mortbay.jetty:jetty:6.1.22@jar",
                    "com.mongodb.casbah:casbah_2.8.0:2.0.2@jar",
                    "org.scala-lang:scala-library:2.8.1@jar"
            ]

List runTime = [
                    "org.scalatra:scalatra_2.8.0:2.0.0.M2@jar",
                    "com.mongodb.casbah:casbah_2.8.0:2.0.2@jar",
                    "org.scala-lang:scala-library:2.8.1@jar"
            ]

//                  "org.mortbay.jetty:servlet-api:2.5-20081211@jar",
 repositories {
    mavenCentral()
    mavenRepo urls: ["http://scala-tools.org/repo-releases","http://mirrors.ibiblio.org/pub/mirrors/maven2","http://repo1.maven.org/maven2","https://oss.sonatype.org/content/repositories/snapshots","https://oss.sonatype.org/content/repositories/releases"]
}

dependencies {
        scalaTools 'org.scala-lang:scala-compiler:2.8.1'
        scalaTools 'org.scala-lang:scala-library:2.8.1'
          compile compileTime
            runtime runTime
          testCompile "junit:junit:3.8.2"   
      } 

task myTask (type: War) {
  println configurations.runtime.collect
  println classpath()
 }

war {
   // from 'main/webapp' 
    webInf { from 'src/main/webapp/WEB-INF' }
  //  classpath classpath() /
    classpath configurations.runtime

    webXml = file('src/main/webapp/WEB-INF/web.xml') 
}

I like to 1) Add only the necessary jars. in the war, in the above code i am getting Jetty and servlet jars in my war. !

like image 961
Rajmahendra Avatar asked Dec 22 '22 18:12

Rajmahendra


1 Answers

For dependencies that should not go into the War, use the "providedCompile" or "providedRuntime" scope.

Some remarks on your build script:

  1. You don't have to put dependencies on the "runtime" class path that are already on the "compile" class path. Gradle does this for you. Same for "providedCompile" and "providedRuntime".
  2. Do you really have compile dependencies on servlet API and Jetty? (Could be true, just wondering.)
  3. Your usage of "mavenRepo urls: ..." is wrong. You need to list the repos one by one. For more information, see 32.5.1 Maven repositories in the Gradle user guide.
  4. Not sure why you use "@jar" everywhere. This effectively disables transitive dependency management. Maybe a result of 3. ?
  5. Your "war { ... }" configuration is the default and can be omitted. See 23.6 War in the user guide.
like image 106
Peter Niederwieser Avatar answered Dec 26 '22 10:12

Peter Niederwieser