5

すべてのサブプロジェクト (約 30) に対して jar タスクを定義しようとしています。次のタスクを試しました。

 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 
            )
            }
    }

私の問題は、サブ プロジェクト間の依存関係がマニフェストのクラスパスに含まれていないことです。ランタイム構成をコンパイル構成に変更しようとしましたが、次のエラーが発生します。

  • 問題: プロジェクト ':EskoordClient' の評価中に問題が発生しました。

    未解決状態でない構成は変更できません!

これは、プロジェクト EskoordClient の完全なビルド ファイルです。

dependencies {     
    compile project(':ePEPClient')
}

私のサブプロジェクトのビルドファイルのほとんどは、プロジェクトの依存関係のみを定義しています。サードパーティの lib 依存関係は、スーパー プロジェクトのビルド ファイルで定義されます。

すべてのサブプロジェクトのスーパープロジェクトのマニフェスト クラスパスに、必要なすべてのクラスパス エントリ (サード パーティのライブラリおよびその他のプロジェクト) を含める可能性はありますか?

4

1 に答える 1

5

これが私がそれを機能させる方法です。次の呼び出しのみを使用して、プロジェクトの依存関係を取得します。

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

    }

}
于 2012-09-06T21:30:55.857 に答える