providedCompile without war plugin

后端 未结 7 1609
忘掉有多难
忘掉有多难 2020-12-23 10:00

I want to reuse certain filter for many projects so I want to extract it and use a single jar to just add it to any Web App.

For building I am using Gradle 1.3 and t

相关标签:
7条回答
  • 2020-12-23 10:10

    When you find yourself using Gradle 2.12, change 'providedCompile' to 'compileOnly'.

    0 讨论(0)
  • 2020-12-23 10:15

    Take a look at the Gradle plugin propdeps from SpringSource. From the project description:

    Provides additional optional and provided dependency configurations for Gradle along with Maven POM generation support.

    0 讨论(0)
  • 2020-12-23 10:19

    I wrote a blog post recently which covers exactly this scenario. It also shows you how to get integration with Eclipse set up properly too.

    http://blog.codeaholics.org/2012/emulating-mavens-provided-scope-in-gradle/

    0 讨论(0)
  • 2020-12-23 10:19

    There is an easier way:

    configurations {    
        provided
        provided.extendsFrom(compile)
    }
    

    and then you can:

    dependencies {  
        provided group: 'javax.servlet', name: 'javax.servlet-api', version:'3.+' 
    }
    

    You will also want to have the provided libraries in the generated project files of Eclipse or Idea:

    idea.module.scopes.PROVIDED.plus += configurations.provided
    eclipse.classpath.plusConfigurations += configurations.provided
    
    0 讨论(0)
  • 2020-12-23 10:26

    There is no such configuration out of the box for the java plugin. However you can build it yourself as follows:

    configurations { providedCompile }
    
    dependencies {
        providedCompile "javax.servlet:javax.servlet-api:3.+"
    }
    
    sourceSets.main.compileClasspath += configurations.providedCompile
    sourceSets.test.compileClasspath += configurations.providedCompile
    sourceSets.test.runtimeClasspath += configurations.providedCompile
    

    This adds the configuration, and puts all the dependencies in there on the compile classpaths of both your main classes and test classes. You also need to add it to the runtimeClasspath, as that doesn't include the compile classpath according to the gradle DSL documentation.

    0 讨论(0)
  • 2020-12-23 10:28

    As of Gradle 2.12 the issue of defining compile only dependencies is finally solved in a simple and natural manner by the new "copmpileOnly" configuration:

    dependencies {
        compileOnly 'javax.servlet:servlet-api:2.5'
    }
    
    0 讨论(0)
提交回复
热议问题