Gradleでは、ディレクトリ内の推移依存関係を含めます

zenn1337:

私は、例えば、依存関係のカップルを持っているJavaプロジェクトを持っています:

dependencies {
    compile("com.whatever.jar:jar-1:1.2.3")
    compile("com.whatever.jar:jar-2:4.5.6")
    compile("com.whatever.jar:jar-3:7.8.9")
} 

私はジャーライブラリとしてそれをパッケージ化し、それらの依存関係を記述しPOMファイルとリポジトリ一緒に公開します:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.my.project</groupId>
    <artifactId>my-library</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>com.whatever.jar</groupId>
            <artifactId>jar-1</artifactId>
            <version>1.2.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.whatever.jar</groupId>
            <artifactId>jar-2</artifactId>
            <version>4.5.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.whatever.jar</groupId>
            <artifactId>jar-3</artifactId>
            <version>7.8.9</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>

私も持っている別のコンパイル時にこの以前に構築されたjarファイルに依存してプロジェクトを:

dependencies {
    compileOnly("com.my.project:my-library:1.0.0")
}

私は2番目のプロジェクトを構築し、両方含むzipファイル作成タスクを作成したいcom.my.project:my-library:1.0.0jarファイルとその推移依存関係(jar-1jar-2およびjar-3)を。

task createZip << {
    into('lib') {
        // here I would like to do something like (it's a horrible pseudo-code):
        from configurations.(com.my.project:my-library:1.0.0).jar.transitiveDependencies.files
    }
}

私はそれをどのように実現するのですか?

編集:私はまたのリストにアクセスしたいmy-libraryの推移依存性(と正確にそれらのではなく、他のプロジェクトで依存関係)をプログラム構築するために、Loader-Pathそれらを使用してマニフェスト属性を。

Chriki:

ここでは、自己完結型ですbuild.gradleあなたの方法を紹介したスクリプトcreateZip(唯一のZIPアーカイブに固有の依存関係を追加します)タスクを作成することができますが。

/* make the "compileOnly" configuration available */
plugins {
    id 'java'
}

/* add some demo dependencies to the project */
repositories {
    jcenter()
}
dependencies {
    compileOnly 'junit:junit:4.12'
    compileOnly 'org.slf4j:slf4j-simple:1.7.28'
}

task createZip(type: Zip) {
    // the "lib" directory in the ZIP file will only have all those dependency
    // files of the "compileOnly" configuration which belong to the
    // "junit:junit:4.12" module:
    def depOfInterest = dependencies.create('junit:junit:4.12')
    into('lib') {
        from configurations.compileOnly.resolvedConfiguration.getFiles({dep ->
            dep == depOfInterest
        })
    }

    // the "justForDemonstration" directory in the ZIP file will have all
    // dependency files of the "compileOnly" configuration, incl. SLF4J:
    into('justForDemonstration') {
        from configurations.compileOnly
    }
}

これは、使用して実行することができます./gradlew createZip(Gradleの5.6.2でテスト済み)。これは、下のZIPファイルを生成しますbuild/distributions/<your_project_name>.zipそれはあなたがあなたの擬似コードを念頭に置いていたものだなら、私に教えてください。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=312784&siteId=1