gradle:将 jar 添加到 web-inf

发布于 2024-10-17 02:17:42 字数 1707 浏览 5 评论 0原文

我创建了一个 gradle 构建并添加了 java、scala、war、jetty 代码,并且一切正常。



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') 
}

我喜欢 1) 仅添加必要的罐子。在战争中,在上面的代码中,我在战争中获得了 Jetty 和 servlet jar。 !

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. !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2024-10-24 02:17:42

对于不应进入战争的依赖项,请使用“providedCompile”或“providedRuntime”范围。

关于构建脚本的一些注释:

  1. 您不必将依赖项放在已经位于“编译”类路径上的“运行时”类路径上。 Gradle 会为你做到这一点。 “providedCompile”和“providedRuntime”相同。
  2. 你真的对 servlet API 和 Jetty 有编译依赖吗? (可能是真的,只是想知道。)
  3. 您对“mavenRepo urls: ...”的使用是错误的。您需要一一列出存储库。有关更多信息,请参阅 Gradle 中的 32.5.1 Maven 存储库用户指南。
  4. 不知道为什么你到处使用“@jar”。这有效地禁用了传递依赖管理。也许是 3 的结果。 ?
  5. 您的“war { ... }”配置是默认配置,可以省略。请参阅用户指南中的 23.6 War

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文