Skip to content

Instantly share code, notes, and snippets.

@hiroyuki-sato
Last active January 22, 2021 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroyuki-sato/3e261ef8eb2d092b3d83ae637b9ffd29 to your computer and use it in GitHub Desktop.
Save hiroyuki-sato/3e261ef8eb2d092b3d83ae637b9ffd29 to your computer and use it in GitHub Desktop.
embulk gradle plugins

./gradlew wrapper --gradle-version=6.01

dependenciesの書き方

dependencies {
//    compile  "org.embulk:embulk-core:0.9.7"
//    provided "org.embulk:embulk-core:0.9.7"
    compileOnly "org.embulk:embulk-core:0.9.23"

    compile 'com.jayway.jsonpath:json-path:2.2.0'

    testCompile "junit:junit:4.+"
    testCompile "org.embulk:embulk-core:0.9.23:tests"
    testCompile "org.embulk:embulk-standards:0.9.23"
    testCompile "org.embulk:embulk-deps-buffer:0.9.23"
    testCompile "org.embulk:embulk-deps-config:0.9.23"
}
  • compileOnly と書くのは、embulkのところだけ?、json-pathもcompileOnlyと書くべき?
  • testCompileのバージョンは0.9.23とかで統一した方が良い?(READMEはembulk-deps-bufferは0.9.22, deps-configは0.9.23になっている)

excludeの仕方

こう出たら、compileをcompileOnlyに変えて、./gradlew dependencies --write-locksを実行すれば良いのかな?

============================================ WARNING ============================================
Following "runtime" dependencies are included also in "compileOnly" dependencies.

  "org.slf4j:slf4j-api:1.7.16"

  "compileOnly" dependencies are used to represent Embulk's core to be "provided" at runtime.
  They should be excluded from "compile" or "runtime" dependencies like the example below.

  dependencies {
    compile("org.glassfish.jersey.core:jersey-client:2.25.1") {
      exclude group: "javax.inject", module: "javax.inject"
    }
  }
=================================================================================================

上記警告が出る時

dependencies {
//    compile  "org.embulk:embulk-core:0.9.7"
//    provided "org.embulk:embulk-core:0.9.7"
    compileOnly "org.embulk:embulk-core:0.9.23"

    compile 'com.jayway.jsonpath:json-path:2.2.0'

    testCompile "junit:junit:4.+"
    testCompile "org.embulk:embulk-core:0.9.23:tests"
    testCompile "org.embulk:embulk-standards:0.9.23"
    testCompile "org.embulk:embulk-deps-buffer:0.9.23"
    testCompile "org.embulk:embulk-deps-config:0.9.23"
}

gemの依存関係

gemの依存関係は、gem {}ないにどう書けば良いのかな。

  spec.add_development_dependency 'bundler', ['~> 1.0']
  spec.add_development_dependency 'rake', ['>= 10.0']
  spec.add_dependency 'jsonpath', ['~> 0.5.8'] # for guess
  spec.add_dependency 'json', ['~> 2.0.2']     # for guess
gem {
    //from("LICENSE")  // Optional -- if you need other files in the gem.
    authors = ["Hiroyuki Sato","Takuma kanari"]
    email = [ "hiroysato@gmail.com","chemtrails.t@gmail.com"]
    // "description" of the gem is copied from "description" of your Gradle project.
    summary = "Example input plugin for Embulk"
    homepage = "https://github.com/hiroyuki-sato/embulk-parser-jsonpath"
    licenses = [ "MIT" ]
}
@dmikurube
Copy link

  • compileOnly は、独自定義だった provided を Gradle 標準の記述 compileOnly で置き換えているものです。通常の場合は embulk-core だけが対象になると思います。
  • README では 0.9.22 には 0.9.22 を、 0.9.23 には 0.9.23 を対応させていると思います。
  • ./gradlew dependencies --write-locks とその warning は関係ありません (dependency lock から外れたときには別のエラーが出てビルド失敗します)
  • Following "runtime" dependencies are included also... の warning は「embulk-core に入っている dependency library を、別のライブラリ (この場合 json-path しかないのでそれ) でも使ってしまっている」ことを意味します。
    • これによって embulk-core にもう入っている slf4j-api が、プラグイン側にも重複して入ってしまうことになります。これは問題を引き起こすことがあるため、警告しています。
    • これが出たら、警告されたライブラリに、遷移的に依存しているライブラリを探してください。今回の場合は json-path しかないので、この json-pathslf4j-api を巻き込んでしまっていることになります。
    • 見つかったライブラリの遷移的な依存から、重複したライブラリを明示的に exclude します。今回の場合はこんな感じ :
      compile('com.jayway.jsonpath:json-path:2.2.0') {
          exclude group: "org.slf4j", module: "slf4j-api"
      }
      
  • gem の依存関係は今まだサポートしてないですね…。ここに issue しました embulk/gradle-embulk-plugins#68

@dmikurube
Copy link

v0.3.0 で gem dependency や、標準ではない (guess とかも書かれた) lib/embulk/???/???.rb も (無理やりですが) サポートされるようになりました。こんな感じで使えるようになるのではないかと思います

gem {
  ...
  generateRubyCode = false  // これで lib/embulk/parser/jsonpath.rb を自動生成するのを止める
  into("lib/embulk/parser/") {
    from "lib/embulk/parser/jsonpath.rb"  // このファイルは消さない
  }
  into("lib/embulk/guess/") {
    from "lib/embulk/guess/jsonpath.rb"  // このファイルも消さない
  }
  dependencies = [  // add_dependency のあとに続く文字列をそのまま書く
    "'jsonpath', ['~> 0.5.8']",
    "'json', ['~> 2.0.2']"
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment