Home Ask Login Register

Developers Planet

Your answer is one click away!

Basit February 2016

convert maven jar and copy resources plugin to gradle

I am new to gradle and trying to convert my POM into gradle.build. I have convert the dependencies part and now converting plugin part. I have following in my POM

                    junit, org.apache.logging.log4j, org.springframework, aopalliance, org.springframework.data, javax.inject, 
                        org.hibernate, javax.el, com.microsoft.sqlserver, org.apache.commons, com.jcraft, com.sun.mail, 
                        org.apache.velocity, commons-lang, commons-logging, commons-collections, org.jboss.logging, 
                        org.jboss, org.javassist, dom4j, javax.transaction



Basit February 2016

Hhmm I tried the following and it worked. I don't know how well this approach is. But if someone has better way to do it then please post answer too.

task wrapper(type: Wrapper) {
    gradleVersion = '2.10'

task copyJars(type: Copy) {
    from configurations.runtime
    into "$buildDir/libs/dependency-jars"

task copyConfigurationFiles(type: Copy) {
    description 'Copies the configurations files src/main/resources directory (from) to the target directory(into).'
    from "src/main/resources"
    into "$buildDir/libs/conf"
    include '**/*.properties', '**/*.xml', '**/*.vm', '**/*.txt'

task copyFiles(dependsOn: [copyJars, copyConfigurationFiles])

jar {

    dependsOn copyFiles

    // Keep jar clean:
    exclude '**/*.properties', '**/*.xml', '**/*.vm', '**/*.txt'

    manifest { 
        attributes ('Implementation-Version': version,
           'Main-Class': "$mainClassName",
           'Class-Path': "conf/" + " " + configurations.runtime.files.collect {"dependency-jars/$it.name" }.join(' ')

After that I simply run task jar. And it created the jar, as well as dependency-jars folder with all jars in it and also conf folder with all configuration files in it. Just like when I did maven install


Post Status

Asked in February 2016
Viewed 2,192 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life