Maven newbie problems, please help


(marzia.forli) #1

I used maven for (too) long… Right now I am in process of porting some builds to gradle and have some basic problems with my build…

  1. processResourcess (java plugin) As I see from the outcomes of mine packaging trials, when using java plugin gradle, default handling of src/main/resources is copy with filtering, but this blasts my project as I have some textual files with ${…} expressions that I would like to leave unfiltered. How can I have basic copying and selectively apply filtering (most idiomatic way) ? Are (and how) the configurations of processResources inheritable ? Why is the filtering default seting ? What is the pseudocode of default processResourcess {} ? How can I debug/trace my code (something like ‘println processResources.getActions()’) ?

  2. ‘provided’ scope Learning from others I stumbled upn this: https://github.com/Netflix/gradle-template/blob/master/gradle/convention.gradle#L51 can somebody confirm that is ‘good/right’ way to handle this kind of deps ?

Thank you, Marzia


(Peter Niederwieser) #2

ad 1. You could do something like:

processResources {
    exclude "path/not/to/be/filtered/**"
    filter ...
}
  task copyResources(type: Copy) {
    from sourceSets.main.resources
    into sourceSets.main.output.resourcesDir
    include "path/not/to/be/filtered/**"
}
  classes.dependsOn(copyResources)

ad 2. Either that, or just use ‘compile’ instead of ‘provided’ and make the War project responsible for excluding transitive dependencies that should not be packaged (or including the ones that should be packaged). One consequence to be aware of is that in case you are publishing to a Maven repository, you’ll get a ‘compile’ scope in the POMs, which can be a problem if you have downstream Maven builds.


(marzia.forli) #3

Thank you very much Peter… I am deeply sorry but my troubles with processResources are completely my fault as I have mistakenly compared wrong reference content against the output of the build… In the end I just added my filtering config:

processResources {
    filesMatching("**/damnConfig.xml") {
        expand('project': [artifactId: project.name, version: version.toString()],
            'prop1': 'val1',
            'prop2': 'val2')
    }
}

Notwithstanding I would like to understand the logic behind pR and what are idiomatic ways of inc/excluding files and applying filtering selectively… any pointers ?

So if I use ‘netflix template’ and publish to maven repository I can expect some pom.xml polishing needs ?

I would like to try my osgi adventure do you have some pointers to some template projects or similar ?

Thanks again, Marzia


(Peter Niederwieser) #4

If ‘filesMatching’ solves the problem, it’s a better solution than what I proposed. I don’t know if the Netflix template handles ‘provided’ in POMs; just give it a try. Regarding OSGi, check out the OSGi chapter in the Gradle User Guide and the samples in the full Gradle distribution.