Add classpath in manifest using Gradle

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

    I know this is likely trivial for the groovy people here, but in my case, I wanted to change the location of the Class-Path in the manifest file depending on whether I was going to run in the production environment or local environment. I did this by making my build.gradle's jar section look like this:

    jar {
      from configurations.runtime
      manifest {
        attributes ('Main-Class': 'com.me.Main',
                    'Class-Path': configurations.runtime.files.collect { jarDir+"/$it.name" }.join(' ')
                   )
      }
    }
    

    In this case, the argument to gradle build is passed like so:

    $ gradle build -PjarDir="/opt/silly/path/"
    

提交回复
热议问题