Add classpath in manifest using Gradle

前端 未结 9 1646
醉话见心
醉话见心 2020-12-01 02:51

I would like my Gradle build script to add the complete Classpath to the manifest file contained in JAR file created after the build.

Example:

Manife         


        
9条回答
  •  悲&欢浪女
    2020-12-01 03:29

    If your project has external library dependencies, you could copy the jars to a folder and add the classpath entries in the manifest.

     def dependsDir = "${buildDir}/libs/dependencies/"
        task copyDependencies(type: Copy) {
        from configurations.compile
        into "${dependsDir}"
       }
    task createJar(dependsOn: copyDependencies, type: Jar) {
      
        manifest {
            attributes('Main-Class': 'com.example.gradle.App',
                    'Class-Path': configurations.compile.collect { 'dependencies/' + it.getName() }.join(' ')
            )
        }
        with jar
    }
    

    More details can be read here

提交回复
热议问题