2015-05-04 18 views
4

我在build.gradle腳本中遇到問題我的腳本基本上是生成POM文件,然後複製該工件到其他位置以及build/lib不同的名稱。我面臨的問題如何調用下面的構建任務,因爲它正在生成錯誤。我正在使用gradle 2.3當使用標準生命週期插件已被棄用並計劃在Gradle 3.0中刪除時,定義自定義的「構建」任務已棄用

錯誤:「定義自定義'建立'任務已棄用,使用標準生命週期插件已棄用,並計劃在Gradle 3.0中刪除「

我的任務生成將生成工件,然後生成P OM並將工件移動到不同的位置,但是我得到的錯誤不是。

我完整的腳本是

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 
} 
+1

什麼消息不清?不要定義自己的構建任務,這將覆蓋標準構建任務。爲它選擇另一個名字。 –

+2

@JB Nizet那麼如何提示標準構建任務取決於其他一些,例如組裝? – Bax

+2

'build.dependsOn assemble' –

回答

相關問題