Gradle: adding jar to web-inf

I created the gradle construct and added java, scala, war, berth code and all its performance.

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 1) Add only the necessary jars. in the war, in the codec above, I get Jetty banks and servlets in my war.

+4
source share
1 answer

For dependencies that should not go to war, use the "provided compiler" or "provided time span" area.

Some notes about your build script:

  • You do not need to set dependencies on the path of the runtime class, which are already on the path to compilation. Gradle does it for you. The same goes for "providedCompile" and "providedRuntime".
  • Do you really have a compilation of servlet and Jetty API dependencies? (Maybe the truth is just interesting.)
  • Your use of "mavenRepo urls: ..." is incorrect. You need to list the repositories one at a time. See 32.5.1 Maven Repositories in the Gradle User Guide for more information.
  • Not sure why you use "@jar" everywhere. This effectively disables transitive dependency management. Maybe the result is 3.?
  • The configuration "war {...}" is the default and may be omitted. See 23.6 War in the user manual.
+11
source

Source: https://habr.com/ru/post/1339313/


All Articles