Not able to build jar outside project via gradle


(Meraj Rasool Khattak) #1

I am migrating my projects from Maven to Gradle. After running gradle init, I have generated a base build.gradle file for my project based on already available pom.xml file.

After this, I have added some custom tasks and am able to compile my project without any errors when I run it with in the project directory e.g. ./gradlew createTigaseJar but when I try to run this outside the directory e.g. ./java/tigase/tigase-server/gradlew createTigaseJar then it throws the error cannot find symbol.

Here is the script:

//tigase-server
project('tigase-server'){

    apply plugin: 'java'
    apply plugin: 'maven'

    group = 'tigase'
    version = '5.2.0'

    description = """Tigase Server"""

    sourceCompatibility = 1.7
    targetCompatibility = 1.7

    repositories {     
        maven { url "http://maven.tigase.org" }
        maven { url "http://build.xmpp-test.net/maven/" }
        maven { url "http://repo.maven.apache.org/maven2" }
        mavenCentral()
        jcenter()
    }

    dependencies {
        compile group: 'org.xerial', name: 'sqlite-jdbc', version:'3.7.2'
        compile group: 'tigase', name: 'tigase-utils', version:'3.4.2'
        compile group: 'tigase', name: 'tigase-xmltools', version:'3.4.4'
        testCompile group: 'junit', name: 'junit', version:'4.11'
        compile(group: 'org.apache.felix', name: 'org.osgi.core', version:'1.4.0') {
        /* This dependency was originally in the Maven provided scope, but the project was not of type war.
        This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
        Please review and delete this closure when resolved. */
        }
        compile(group: 'org.slf4j', name: 'jul-to-slf4j', version:'1.7.5') {
        /* This dependency was originally in the Maven provided scope, but the project was not of type war.
        This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
        Please review and delete this closure when resolved. */
        }

    }

    sourceSets {
        main {
            java {
                srcDir "$rootProject.projectDir/java/tigase/tigase-server/"
            }

            //compileClasspath += libDependencyJars
        }
    }

    task preBuildCleanup << {
        delete "$rootProject.projectDir/java/tigase/tigase-server/build/"
        delete "$rootProject.projectDir/java/tigase/tigase-server/dist/"
    }

    task createTigaseJar(dependsOn: ['preBuildCleanup', 'build']){
        jar {
            manifest {
                //attributes("Class-Path": sourceSets.main.compileClasspath.collect { 'lib/' + it.getName() }.join(' '))
            }

            destinationDir = file("$rootProject.projectDir/java/tigase/tigase-server/dist/")
        }
    }
}

I need to run this from outside its project as it will be part of some other build scripts. I have other java projects and they all run this way but having issues with this one. I am not sure what I am missing here.

Can any one help in this regard? Thanks