2014-10-29 4 views
6

내가 찾고있는 것은 내 프로젝트의 미리 만든 manifest.mf 파일과 gradle의 jar 작업의 동적으로 생성 된 매니페스트 파일을 결합하는 것입니다.Gradle Manifest.MF

이렇게 할 방법이 있습니까? 현재 내가 완전히 내 매니페스트 파일을 생성 해요 : -

jar.doFirst { 
    manifest { 
     def requiredProjects = '' 
     configurations.compile.getAllDependencies().withType(ProjectDependency).each {dep-> 
      def dependantProjects = dep.getDependencyProject() 
      def projects = project(dependantProjects.path).libsDir.list().findAll{it.endsWith('.jar')} 
      projects.removeAll(projects.findAll{it.endsWith('test.jar')}) 
      def requiredProject = projects.join(' ') 
      requiredProjects += requiredProject.replaceAll(/ /,'%20') + ' ' 
      logger.info 'Required Project: ' + requiredProject 
     } 
     logger.info 'Required requiredProjects: ' + requiredProjects 

     def compileFiles = configurations.compile.files{ it instanceof ExternalDependency }.collect { 
      File file = it 
      "lib/${file.name}" 
     }.join(' ') 

     def manifestPath = requiredProjects + compileFiles 
     logger.info 'Manifest: '+ manifestPath 
     attributes 'Class-Path': manifestPath 
     attributes 'Build-date': new Date(); 
     attributes 'Application-Version': project.version 
    } 
} 

나는 내가 /META-INF/MANIFEST.MF 파일을해야합니다 것을 알고있다.

원래 Gradle 용 OSGI 플러그인을 사용하고 있었지만 이것은 매니 페스트 파일을 무시하고 큰 혼란을 일으키는 것으로 보입니다.

편집

나는이 꽤으로 검토 한 덕분에 다음 코드 나 기존 MANIFEST.MF를 읽을 수 있도록 내가 찾은 카를로 -

jar { 
     onlyIf { !compileJava.source.empty } 
     manifest { 
      // benutze das im Projekt vorliegende File, falls vorhanden: 
      def manif = "${projectDir}/META-INF/MANIFEST.MF" 
      if (new File(manif).exists()) {     
       from (manif) { 
        eachEntry { details ->       
         if (details.key == 'Bundle-Vendor') { 
                details.value = 'xyz GmbH' 
         } 
        } 
       }          
      } 
      else { 
       logger.info(project.name + " doesn't have a META-INF/MANIFEST.MF.") 
       manifest.attributes provider: xyz GmbH' 
       manifest.attributes project: project.name 
       manifest.attributes Build: new Date() 
      } 
     } 
     // copy if we have these:   
     from file ('plugin.xml')    
     from file ('plugin.properties')  
     into ('icons') { // if any ... 
      from fileTree('icons') 
     } 
    } 

http://forums.gradle.org/gradle/topics/how_to_deal_with_eclipse_projects_and_manifest_files

저는 Gradle을 사용하여 OSGi 프로젝트를 구축하는 데 도움이되는 'wuff'프로젝트도 발견했습니다.

jar.doFirst { 
    manifest { 
     def manifestFile = "${projectDir}/META-INF/MANIFEST.MF" 
     if (new File(manifestFile).exists()) 
      from (manifestFile) 
     def requiredProjects = '' 
     configurations.compile.getAllDependencies().withType(ProjectDependency).each {dep-> 
      def dependantProjects = dep.getDependencyProject() 
      def projects = project(dependantProjects.path).libsDir.list().findAll{it.endsWith('.jar')} 
      projects.removeAll(projects.findAll{it.endsWith('test.jar')}) 
      def requiredProject = projects.join(' ') 
      requiredProjects += requiredProject.replaceAll(/ /,'%20') + ' ' 
      logger.info 'Required Project: ' + requiredProject 
     } 
     logger.info 'Required requiredProjects: ' + requiredProjects 

     def compileFiles = configurations.compile.files{ it instanceof ExternalDependency }.collect { 
      File file = it 
      "lib/${file.name}" 
     }.join(' ') 

     def manifestPath = requiredProjects + compileFiles 
     logger.info 'Manifest: '+ manifestPath 
     attributes 'Class-Path': manifestPath 
     attributes 'Build-date': new Date(); 
     attributes 'Application-Version': project.version 
    } 
} 

중요한 라인 인 : - -이 :

def manifestFile = "${projectDir}/META-INF/MANIFEST.MF" 
if (new File(manifestFile).exists()) 
    from (manifestFile) 

이 날 수 있습니다

결국

https://github.com/akhikhl/wuff

답변

3

나는 다음과 같은 코드를 사용하여 원하는 것을 얻을 관리했습니다 기존 /META-INF/MANIFEST.MF 파일을 상속하고 동적으로 gradle로 관리되는 클래스 경로 종속성을 포함합니다.

관련 문제