Add Classpath in Manifest file of jar in gradle

别来无恙 提交于 2020-01-17 02:52:49

问题


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

回答1:


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(' ')
      )
   }
}


来源:https://stackoverflow.com/questions/30087427/add-classpath-in-manifest-file-of-jar-in-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!