RE: Custom Gradle Task and running dependent Liferay Tasks

Kevin Neibarger, modified 6 Years ago. Regular Member Posts: 105 Join Date: 2/2/18 Recent Posts

Since the Gradle build scripts build and compile JARs for Liferay 7.1 service builder and associated portlets I'm looking to create a custom task under "build" that removes JARs from the osgi/modules directory in the Tomcat server bundle and copy the new JARs built from the build/deploy task. Since the deploy task creates the JARs in the Workspace/bundles/osgi/modules directory, I need to move them to the LIFERAY_HOME/bundles/liferay-ce-portal-7.1.0-ga1/osgi/modules directory.

 

The build/deploy tasks are somehow internal to the Liferay IDE when Gradle is used during mvc-portlet and service-builder creation. When I define my custom task in the build.gradle, the dependsOn(':deploy') it's telling me the deploy task isn't found. Is there a way to run the deploy task automatically before this custom task?

 

FAILURE: Build failed with an exception.

 

* What went wrong:

Could not determine the dependencies of task ':moveJarsToDeploy'.

> Task with path 'deploy' not found in root project 'KHM-portlet-v71'.

 

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

 

Here is the custom task

 

task moveJarsToDeploy (type: Copy){

    dependsOn('deploy')

    group = 'build'

    description = 'Moves the portlet and service jars to the osgi modules directory on your Tomcat server'

   

    // Delete files from Deploy Dir

    fileTree("$deployDir").each { file -> 

    if (file.isFile()) {

    delete file

    }

}

// Copy files to deployDir

fileTree("$jarsDir").each { file -> 

    if (file.isFile()){

    println "COPY $file.path To $deployDir"

    sleep(2 * 1000)

    from file 

    into deployDir

    }

}

}

Kevin Neibarger, modified 6 Years ago. Regular Member Posts: 105 Join Date: 2/2/18 Recent Posts
For those having similar problems, I figured out my issue. Using the call getTasksByName will retrieve the tasks created by Liferay. Below is a snippet of my build.gradle

ext {    deployDir = "$buildDir/../../../../bundles/liferay-ce-portal-7.1.0-ga1/osgi/modules"    jarsDir = "$buildDir/../../bundles/osgi/modules/"}
task deployJars() {   group = 'build'    description = 'Moves the portlet and service jars to the osgi modules directory on your Tomcat server'      doLast {copy {    // Delete files from Deploy Dir    fileTree("$deployDir").each { file ->     if (file.isFile()) {    delete file    }}// Copy files to deployDirfileTree("$jarsDir").each { file ->     if (file.isFile()){    println "COPY $file.path To $deployDir"    sleep(2 * 1000)    from file     into deployDir    }}}}}deployJars.dependsOn getTasksByName('clean', true)deployJars.dependsOn getTasksByName('deploy', true)