Add classpath in manifest using Gradle

前端 未结 9 1645
醉话见心
醉话见心 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:20

    In the latest versions of gradle, compile and runtime becomes deprecated. Instead, use runtimeClasspath as follows:

    'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
    

    EDIT:

    Note that if you are using Kotlin DSL, you can configure the manifest as follows:

    configure {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
        manifest {
            attributes(
                    "Manifest-Version" to "1.0",
                    "Main-Class" to "io.fouad.AppLauncher")
        }
    }
    

    tasks.withType(Jar::class) {
        manifest {
            attributes["Manifest-Version"] = "1.0"
            attributes["Main-Class"] = "io.fouad.AppLauncher"
        }
    }
    

提交回复
热议问题