0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gradleでjarから特定のパッケージだけを取り除く

Last updated at Posted at 2018-02-11

gradleで外部のライブラリjarから特定のパッケージやクラスを取り除く方法メモ。

今回は、kotlin compilerから com/intellij/** 配下のパッケージを取り除いたjarを生成する。

スクリーンショット 2018-02-11 23.37.46.png

build.gradle

configurations {
    kotlinCompiler { transitive = false }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    kotlinCompiler ("org.jetbrains.kotlin:kotlin-compiler:$kotlin_version")
    compile files("$libsDir/tweaked-kotlin-compiler.jar")
}

task tweakKotlinCompiler(type: Jar) {
    from zipTree(configurations.kotlinCompiler.singleFile).matching {
        exclude "com/intellij/**"
    }
    destinationDir libsDir
    archiveName 'tweaked-kotlin-compiler.jar'
}

compileKotlin.dependsOn tweakKotlinCompiler

kotlin-compiler-1.2.10.jar をzipTreeで特定のパッケージを除外し、新たなjarを生成する。

スクリーンショット 2018-02-11 23.37.14.png

特定のパッケージだけ取得したい場合は、includeすれば可能。

全体

build.gradle
buildscript {
    ext.kotlin_version = '1.2.10'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id 'org.jetbrains.intellij' version '0.2.18'
}

group 'com.github.bassaer'
version '0.0.1'

apply plugin: 'kotlin'

repositories {
    mavenCentral()
}

configurations {
    kotlinCompiler { transitive = false }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    kotlinCompiler ("org.jetbrains.kotlin:kotlin-compiler:$kotlin_version")
    compile files("$libsDir/tweaked-kotlin-compiler.jar")
}

task tweakKotlinCompiler(type: Jar) {
    from zipTree(configurations.kotlinCompiler.singleFile).matching {
        exclude "com/intellij/**"
    }
    destinationDir libsDir
    archiveName 'tweaked-kotlin-compiler.jar'
}


compileKotlin() {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
intellij {
    version '2017.3.3'
}
patchPluginXml {
    changeNotes """
      Add change notes here.<br>
      <em>most HTML tags may be used</em>"""
}

compileKotlin.dependsOn tweakKotlinCompiler
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?