Defining a custom build task is deprecated when using the standard lifecycle plugin is deprecated and needs to be removed in Gradle 3.0

I ran into a problem in my build.gradle script My script basically generates a POM file and then copies the artifact to another location, as well as to build / lib with a different name. The problem I am facing How to invoke the following beacuse build task, it causes an error. I am using gradle 2.3

Error: "Defining a custom" build task is deprecated when using the standard lifecycle plugin is deprecated and needs to be removed in gradle 3.0 "

My task build will build an artifact and then generate a POM and move the artifact to another location, but I get below errors.

My full script is

apply plugin: 'cpp'
apply plugin: 'java'
//-- set the group for publishing
group = 'com.tr.anal'

/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream {
        stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.analBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.analBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.t.anal"
version = buildProperties.analBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

repositories {
    maven {
      url "http://cm.thon.com:900000/artifactory/libs-snapshot-local"
    }
     maven {
      url "http://cm.thon.com:9000000/artifactory/libs-release"
    }
}
    dependencies {
   compile ([
    "com.tr.anal:analytics-engine-common:4.+"
      ])
}



model {
  repositories {
    libs(PrebuiltLibraries) {
      jdk {
        headers.srcDirs "${System.properties['java.home']}/../include",
        "${System.properties['java.home']}/../include/win32",
        "${System.properties['java.home']}/../include/darwin",
        "${System.properties['java.home']}/../include/linux"
      }
    }
  }
}

model {
  platforms {
    x64 { architecture "x86_64" }
    x86 { architecture "x86" }
  }
}

model {
  components {
    main(NativeLibrarySpec) {
      sources {
        cpp {
          source {
            lib library: 'main', linkage: 'static'
            lib library: 'jdk', linkage: 'api'
            srcDir "src/main/c++/native"
            include "**/JniSupport.cpp"
            include "**/DiseaseStagingJni.cpp"
          }
        }
      }
    }
  }
}

def nativeHeadersDir = file("$buildDir/nativeHeaders")
//def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(";")
binaries.all {
    // Define toolchain-specific compiler and linker options
    if (toolChain in Gcc) {
        cppCompiler.args "-I${nativeHeadersDir}"
        cppCompiler.args "-g"
        linker.args '-Xlinker', '-shared -LNativeJNI/src/main/resources/DSresources/DSLib -lds64 -Wl'
}
}

//def nativeHeadersDir = file("$buildDir/nativeHeaders")
task nativeHeaders {
    // def nativeHeadersDir = file("$buildDir/nativeHeaders")
     def outputFile = file("$nativeHeadersDir/DiseaseStagingJniWrapper.h")
     def classes = [
             'com.truvenhealth.analyticsengine.common.diseasestaging.DiseaseStagingJniWrapper'
                  ]
     inputs.files sourceSets.main.output
     inputs.property('classes', classes)
     outputs.file outputFile
     doLast {
         outputFile.parentFile.mkdirs()
         def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(":")
         println "Using Compile Path: ${compilePath}"
         exec {
             executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
             args '-o', outputFile
             args '-classpath', compilePath
             args classes
         }
     }
 }

             tasks.withType(CppCompile) { task ->
                 task.dependsOn nativeHeaders
             }
/*****************************
 * Packaging
 *****************************/

apply plugin: "maven"


// Workaround for Jenkins-Artifactory plugin not picking up the POM file

def pomFile = file("${buildDir}/libs/${archivesBaseName.toLowerCase()}-${version}.pom")
task newPom << {
  pom {
      project {
          groupId project.group
          artifactId project.name
          version project.version
          description = "Configuration Management Gradle Plugin"
      }
  }.writeTo(pomFile)
}
//disabling the install task since we're not using maven for real
install.enabled = false

//for publishing to artifactory via jenkins
if(project.hasProperty('artifactoryPublish')) {
  artifactoryPublish {
    mavenDescriptor pomFile
  }
}
def filechange = file("build/libs/NativeJNI-${project.version}.so")
task copyfile(type: Copy) {
     from 'build/binaries/mainSharedLibrary'
     into 'build/libs'
include('libmain.so')
rename ('libmain.so', "$filechange")
 }
//build.dependsOn copyfile
task build (dependsOn: ["newPom","copyfile"]) << {
    println "build in progress"
}

def someFile = file("build/libs/NativeJNI-${project.version}.so")
artifacts {
    archives someFile
}
+4

All Articles