本文介绍了在Gradle中的jar的Manifest文件中添加Classpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的gradle脚本,我需要在以下格式的jar文件的MANIFEST.MF中添加数据我尝试了下面的方法,但无法实现它。我需要下面的方式。我使用gradle 2.3

  

您应该将清单配置放入 jar 阻止自己而不是在 doFirst :

  jar {
清单{
属性(
Manifest-Version:1.0,
Class-Path:configurations.compile.collect {it.getName()} .join('')

}
}


Below is my gradle script and I need to add the data in MANIFEST.MF of jar file in below format I tried the below method but not able to achieve it. i need it in below way. I am using the gradle 2.3

    apply plugin: 'java'

    sourceCompatibility = 1.7
    jar.doFirst {
          manifest {
                attributes("Manifest-Version": "1.0",
                          "Class-Path": configurations.compile.collect { it.getName() }.join(' '))
          }
    }


    repositories {

         maven { url "http://cmp.tsh.thomson.com:80/artifactory/libs-release" }
         maven { url "http://cmp.tsh.thomson.com:80/artifactory/libs-stage" }
         maven { url "http://cmp.tsh.thomson.com:80/artifactory/libs-snapshot" }
         maven { url "http://cmp.tsh.thomson.com:80/artifactory/simple/ext-release-local/" }

    }
    dependencies {
        compile group: 'com.tru.analytics', name: 'analytics-engine-common', version:'4.+'
        compile group: 'com.tru.analytic', name: 'analytics-engine-LicenseVerifier', version:'4.+'
       compile group: 'com.tru.analytics', name: 'MegNativeJNI', version: '4.+', ext: 'so'
       compile group: 'com.tru.analytics', name: 'NativeJNI', version: '4.+', ext: 'so'
        compile(group: 'com.operasolutions', name: 'RiskAnalytics', version:'1.1') {
    exclude(module: 'jyson')
        }
        compile group: 'org.springframework', name: 'spring-context', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-beans', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-core', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-aop', version:'3.2.5.RELEASE'
        compile group: 'org.springframework', name: 'spring-expression', version:'3.2.5.RELEASE'
        compile group: 'org.apache.commons', name: 'commons-collections4', version:'4.0'
        compile group: 'commons-io', name: 'commons-io', version:'2.4'
        compile group: 'net.sf.supercsv', name: 'super-csv-dozer', version:'2.1.0'
        compile group: 'net.sf.supercsv', name: 'super-csv', version:'2.1.0'
        compile group: 'org.aspectj', name: 'aspectjtools', version:'1.6.2'
        compile group: 'org.python', name: 'jython-standalone', version:'2.5.3'
        compile group: 'com.google.code.gson', name: 'gson', version:'1.7.2'
        compile group: 'log4j', name: 'log4j', version:'1.2.16'
        compile group: 'com.xhaus', name: 'jyson', version:'1.0.2'
        compile group: 'com.google.guava', name: 'guava', version:'17.0'
        compile group: 'com.jamonapi', name: 'jamon', version:'2.4'
        compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.1'
        compile group: 'ch.qos.logback', name: 'logback-core', version:'1.1.1'
        compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.6'
        compile group: 'org.codehaus.mojo', name: 'properties-maven-plugin', version:'1.0-alpha-2'
        compile group: 'args4j', name: 'args4j', version:'2.0.28'
        compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version:'1.9.5'
        testCompile group: 'junit', name: 'junit', version:'4.11'
        testCompile group: 'org.mockito', name: 'mockito-all', version:'1.9.5'
    }
    dependencies {
        runtime group: 'com.tru.analytics', name: 'analytics-engine-common', version:'4.+'
        runtime group: 'com.tru.analytics', name: 'analytics-engine-LicenseVerifier', version:'4.+'
       runtime group: 'com.tru.analytics', name: 'MegNativeJNI', version: '4.+', ext: 'so'
      runtime group: 'com.tru.analytics', name: 'NativeJNI', version: '4.+', ext: 'so'
      runtime (group: 'com.operasolutions', name: 'RiskAnalytics', version:'1.1') {
      exclude(module: 'jyson')
        }
        runtime group: 'org.springframework', name: 'spring-context', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-beans', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-core', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-aop', version:'3.2.5.RELEASE'
        runtime group: 'org.springframework', name: 'spring-expression', version:'3.2.5.RELEASE'
        runtime group: 'org.apache.commons', name: 'commons-collections4', version:'4.0'
        runtime group: 'commons-io', name: 'commons-io', version:'2.4'
        runtime group: 'net.sf.supercsv', name: 'super-csv-dozer', version:'2.1.0'
        runtime group: 'net.sf.supercsv', name: 'super-csv', version:'2.1.0'
        runtime group: 'org.aspectj', name: 'aspectjtools', version:'1.6.2'
        runtime group: 'org.python', name: 'jython-standalone', version:'2.5.3'
        runtime group: 'com.google.code.gson', name: 'gson', version:'1.7.2'
        runtime group: 'log4j', name: 'log4j', version:'1.2.16'
        runtime group: 'com.xhaus', name: 'jyson', version:'1.0.2'
        runtime group: 'com.google.guava', name: 'guava', version:'17.0'
        runtime group: 'com.jamonapi', name: 'jamon', version:'2.4'
        runtime group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.1'
        runtime group: 'ch.qos.logback', name: 'logback-core', version:'1.1.1'
        runtime group: 'org.slf4j', name: 'slf4j-api', version:'1.7.6'
        runtime group: 'org.codehaus.mojo', name: 'properties-maven-plugin', version:'1.0-alpha-2'
        runtime group: 'args4j', name: 'args4j', version:'2.0.28'
        runtime group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version:'1.9.5'
       }

    task copyDeps(type: Copy) {
       def dirName = "build/libs/lib"
       file(dirName).mkdirs()
       from configurations.runtime
       into 'build/libs/lib'
    }

    task copylib(type: Copy) {
       dependsOn copyDeps
       def finaldir = file("build/libs/AnalyticsLib-${project.version}-bin")
       file (finaldir).mkdirs()
       from 'build/libs'
       into finaldir
    }

 // adding test report to taskGraph
build.dependsOn copylib

Need below result or data in MANIFEST.MF

Manifest-Version: 1.0
Built-By: jenkins
Build-Jdk: 1.7.0_45
Class-Path: lib/Common-4.0.0-1159.jar lib/uuid-3.2.jar lib/lombok-1.12
 .2.jar lib/jackson-core-2.2.3.jar lib/jackson-annotations-2.2.3.jar l
 ib/jackson-databind-2.2.3.jar lib/LicenseVerifier-4.0.0-1159.jar lib/
 license3j-1.0.4.jar lib/bcpg-jdk16-1.46.jar lib/bcprov-jdk16-1.46.jar
  lib/RiskAnalytics-1.1.jar lib/javacsv-2.0.jar lib/spring-context-3.2
 .5.RELEASE.jar lib/spring-beans-3.2.5.RELEASE.jar lib/spring-core-3.2
 .5.RELEASE.jar lib/commons-logging-1.1.1.jar lib/spring-aop-3.2.5.REL
 EASE.jar lib/aopalliance-1.0.jar lib/spring-expression-3.2.5.RELEASE.
 jar lib/commons-collections4-4.0.jar lib/commons-io-2.4.jar lib/super
 -csv-dozer-2.1.0.jar lib/dozer-5.4.0.jar lib/commons-beanutils-1.8.3.
 jar lib/commons-lang3-3.1.jar lib/jcl-over-slf4j-1.6.6.jar lib/super-
 csv-2.1.0.jar lib/aspectjtools-1.6.2.jar lib/jython-standalone-2.5.3.
 jar lib/gson-1.7.2.jar lib/log4j-1.2.16.jar lib/jyson-1.0.2.jar lib/g
 uava-17.0.jar lib/jamon-2.4.jar lib/logback-classic-1.1.1.jar lib/log
 back-core-1.1.1.jar lib/slf4j-api-1.7.6.jar lib/properties-maven-plug
 in-1.0-alpha-2.jar lib/maven-model-2.0.6.jar lib/maven-plugin-api-2.0
 .6.jar lib/maven-project-2.0.6.jar lib/maven-settings-2.0.6.jar lib/m
 aven-profile-2.0.6.jar lib/maven-artifact-manager-2.0.6.jar lib/maven
 -repository-metadata-2.0.6.jar lib/wagon-provider-api-1.0-beta-2.jar
 lib/maven-plugin-registry-2.0.6.jar lib/maven-artifact-2.0.6.jar lib/
 plexus-container-default-1.0-alpha-9-stable-1.jar lib/classworlds-1.1
 -alpha-2.jar lib/plexus-utils-1.5.6.jar lib/args4j-2.0.28.jar lib/jac
 kson-mapper-asl-1.9.5.jar lib/jackson-core-asl-1.9.5.jar
解决方案

You should probably put the manifest configuration in jar block itself rather than in doFirst:

jar {
   manifest {
      attributes(
         "Manifest-Version": "1.0",
         "Class-Path": configurations.compile.collect { it.getName() }.join(' ')
      )
   }
}

这篇关于在Gradle中的jar的Manifest文件中添加Classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 02:57