Defining custom classpath for jar manifest in gradle

I am trying to define a jar task for all subprojects (around 30). I tried to perform the following task:

 jar {
            destinationDir = file('../../../../_temp/core/modules')
            archiveName = baseName + '.' + extension
            metaInf {
                    from 'ejbModule/META-INF/' exclude 'MANIFEST.MF'
            }

          def manifestClasspath = configurations.runtime.collect { it.getName() }.join(',') 
            manifest {
            attributes("Manifest-Version"       : "1.0",
                "Created-By"             : vendor,
                "Specification-Title"    : appName,
                "Specification-Version"  : version,
                "Specification-Vendor"   : vendor,
                "Implementation-Title"   : appName,
                "Implementation-Version" : version,
                "Implementation-Vendor"  : vendor,
                "Main-Class"             : "com.dcx.epep.Start",
                "Class-Path"             : manifestClasspath 
            )
            }
    }

My problem is that dependencies between helper projects are not included in the manifest class path. I tried changing the configuration of the runtime to the compilation configuration, but this leads to the following error.

  • What went wrong: There was a problem evaluating the project ': EskoordClient'.

    You cannot change a configuration that is not in an unauthorized state!

      

This is my complete build file for the EskoordClient project:

dependencies {     
    compile project(':ePEPClient')
}

Most of my subproject projects only create files to define project dependencies. Third-party library dependencies are defined in the superproject assembly file.

( ) .

+5
1

. :

getAllDependencies().withType(ProjectDependency)

libsDir Class-Path.

jar {
    manifest {
        attributes 'Main-Class': 'com.my.package.Main'
        def manifestCp = configurations.runtime.files.collect  {
        File file = it
        "lib/${file.name}"
        }.join(' ')


         configurations.runtime.getAllDependencies().withType(ProjectDependency).each {dep->

            def depProj = dep.getDependencyProject()
            def libFilePaths = project(depProj.path).libsDir.list().collect{ inFile-> "lib/${inFile}"  }.join(' ')
            logger.info"Adding libs from project ${depProj.name}: [- ${libFilePaths} -]"
            manifestCp += ' '+libFilePaths
        }

        logger.lifecycle("")
        logger.lifecycle("---Manifest-Class-Path: ${manifestCp}")
        attributes 'Class-Path': manifestCp

    }

}
+6

All Articles