{"id":24912317,"url":"https://github.com/jruby/jar-dependencies","last_synced_at":"2025-08-01T15:09:55.958Z","repository":{"id":52410042,"uuid":"16169858","full_name":"jruby/jar-dependencies","owner":"jruby","description":"manage jar dependencies for ruby gems","archived":false,"fork":false,"pushed_at":"2025-02-10T21:37:00.000Z","size":3415,"stargazers_count":35,"open_issues_count":13,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-26T17:51:45.329Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jruby.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-01-23T10:51:24.000Z","updated_at":"2025-02-10T21:37:04.000Z","dependencies_parsed_at":"2024-11-30T18:05:49.624Z","dependency_job_id":"80e8dcc2-78ec-4802-9b24-972d56ce3c9c","html_url":"https://github.com/jruby/jar-dependencies","commit_stats":{"total_commits":418,"total_committers":17,"mean_commits":24.58823529411765,"dds":"0.44976076555023925","last_synced_commit":"b1e99921627a481f2746f1b729920b4b95e93c83"},"previous_names":["jruby/jar-dependencies","mkristian/jar-dependencies"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/jruby/jar-dependencies","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjar-dependencies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjar-dependencies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjar-dependencies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjar-dependencies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jruby","download_url":"https://codeload.github.com/jruby/jar-dependencies/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjar-dependencies/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268231376,"owners_count":24217032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-02T05:04:55.202Z","updated_at":"2025-08-01T15:09:55.939Z","avatar_url":"https://github.com/jruby.png","language":"Ruby","readme":"# jar-dependencies\n\n* [![Build Status](https://secure.travis-ci.org/mkristian/jar-dependencies.svg)](http://travis-ci.org/mkristian/jar-dependencies)\n* [![Code Climate](https://codeclimate.com/github/mkristian/jar-dependencies.svg)](https://codeclimate.com/github/mkristian/jar-dependencies)\n\nadd gem dependencies for jar files to ruby gems.\n\n\n## Getting control back over your jar\n\njar dependencies are declared in the gemspec of the gem using the same notation\nas \u003chttps://github.com/mkristian/jbundler\u003e.\n\nWhen using `require_jar` to load the jar into JRuby's classloader a version conflict\nwill be detected and only **ONE** jar gets loaded.\n**jbundler** allows to select the version suitable for you application.\n\nMost maven-artifacts do **NOT** use versions ranges but depend on a concrete version.\nIn such cases **jbundler** can always **overwrite** any such version.\n\n\n## Vendoring your jars before packing the jar\n\nAdd the following to your *Rakefile*:\n\n    require 'jars/installer'\n    task :install_jars do\n      Jars::Installer.vendor_jars!\n    end\n\nThis will install (download) the dependent jars into **JARS_HOME** and create a\nfile **lib/my_gem_jars.rb**, which will be an enumeration of `require_jars`\nstatements to load all the jars.\nThe **vendor_jars** task will copy them into the **lib** directory of the gem.\n\nThe location where jars are cached is per default **$HOME/.m2/repository** the\nsame default as Maven uses to cache downloaded jar-artifacts.\nIt respects **$HOME/.m2/settings.xml** from Maven with mirror and other settings\nor the environment variable **JARS_HOME**.\n\n**IMPORTANT**: Make sure that jar-dependencies is only a **development dependency**\nof your gem. If it is a runtime dependency the require_jars file will be overwritten\nduring installation.\n\n\n## Reduce the download and reuse the jars from maven local repository\n\nIf you do not want to vendor jars into a gem then **jar-dependency** gem can vendor\nthem when you install the gem. In that case do not use\n`Jars::Installer.install_jars` from the above rake tasks.\n\n**NOTE**: Recent JRuby comes with **jar-dependencies** as default gem, for older\nversions for the feature to work you need to gem install **jar-dependencies** first\nand for bundler need to use the **bundle-with-jars** command instead.\n\n**IMPORTANT**: Make sure that jar-dependencies is a **runtime dependency** of your\ngem so the require_jars file will be overwritten during installation with the\n\"correct\" versions of the jars.\n\n\n## For development you do not need to vendor the jars at all\n\nSet the environment variable\n\n    export JARS_VENDOR=false\n\nto tell the jar_installer not vendor any jars, but only create the file with the\n`require_jar` statements. This `require_jars` method will find the jar inside the\nmaven local repository and load it from there.\n\n\n## Some drawbacks\n\n * First you need to install the jar-dependency gem with its development dependencies installed (then ruby-maven gets installed as well)\n * Bundler does not install the jar-dependencies (unless JRuby adds the gem as default gem)\n * You need ruby-maven doing the job of dependency resolution and downloading them. gems not part of \u003chttp://rubygems.org\u003e will not work currently\n\n\n## JARs other than from maven-central\n\nBy default all jars need to come from maven-central (\u003csearch.maven.org\u003e), in order\nto use jars from any other repo you need to add it into your Maven *settings.xml*\nand configure it in a way that works without an interactive prompt (username +\npasswords needs to be part of the settings.xml file).\n\n**NOTE:** Gems depending on jars other then maven-central will **NOT** work when\nthey get published on rubygems.org since the user of those gems will not have the\nright settings.xml to allow them to access the jar dependencies.\n\n\n## Examples\n\nAn [example with rspec and all](example/Readme.md) walks you through setup and\nshows how development works and shows what happens during installation.\n\nThere are some more examples with the various [project setups for gems and application](examples/README.md).\nThis includes using proper Maven for the project or ruby-maven with rake or\nthe rake-compiler in conjunction with jar-dependencies.\n\n# Lock down versions\n\nWhenever there are version ranges for jar dependencies it is advisable to lock down the versions of dependencies.\nFor the jar dependencies inside the gemspec declaration this can be done with:\n\n    lock_jars\n\nThis is also working in **any** project which uses a gem with\njar-dependencies. It also uses a Jarfile if present. See the [sinatra\napplication from the examples](examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/).\n\nThis means for a project using bundler and jar-dependencies the setup is\n\n     bundle install\n     lock_jars\n\nThis will install both gems and jars for the project.\n\nUpdate a specific version is done with (use only the artifact_id)\n\n    lock_jars --update slf4j-api\n\nAnd look at the dependencies tree\n\n    lock_jars --tree\n\nAs ```lock_jars``` uses ruby-maven to resolve the jar dependencies.\nSince jar-dependencies does not declare ruby-maven as runtime dependency\n(you just not need ruby-maven during runtime only when you want to\nsetup the project it is needed) it is advicable to have it as\ndevelopment dependency in your Gemfile.\n\n# Proxy and mirror setup\n\nProxies and mirrors can be set up by the usual configuration of maven itself: [settings.xml](https://maven.apache.org/settings.html) - see the mirrors and proxy sections.\n\nAs jar-dependencies does only deal with jar and all jars need to come from maven central, it is only neccessary to mirror maven-central. An example of such a [settings-example.xml](setting.xml is here).\n\nYou also can add such a settings.xml to your project which jar-dependencies will use instad of the default maven locations. This allows to have a per-project configuration and also removes the need to users of your Ruby project to dive into maven in case you have company policy to use a local mirror for gem and jar artifacts.\n\njar-dependencies itself uses maven **only** for the jars and all gems are managed by RubyGems or Bundler or your favourite management tool. So any proxy/mirror settings which should affect gems need to be done in those tools.\n\n# Gradle, Maven, etc\n\nFor dependency management frameworks like gradle (via\njruby-gradle-plugin) or maven (via jruby-maven-plugins\nor jruby9-maven-plugins) or probably ivy or sbt can use the gem\nartifacts from a maven repository like\n[rubygems-proxy from torquebox](http://rubygems-proxy.torquebox.org/)\nor\n[rubygems.lasagna.io/proxy/maven/releases](http://rubygems.lasagna.io/proxy/maven/releases/).\n\nEach of these tools (including jar-dependencies) does the dependency\nresolution slightly different and in rare cases can produce different\noutcomes. But overall each tool can manage both jars and gems and\ntheir transitive dependencies.\n\nPopular gems like jrjackson or nokogiri do not declare their jars in\nthe gemspec files and just load the bundle jars into jruby\nclassloader, can easily create problems as the jackson and\nxalan/xerces libraries used by those gems are popular ones in the Java world.\n\n# Troubleshooting\n\nSince maven is used under the hood it is possible to get more insight\nwhat maven is doing. Show the regular maven output:\n\n    JARS_VERBOSE=true bundle install\n    JARS_VERBOSE=true gem install some_gem\n\nOr, with maven debug enabled\n\n    JARS_DEBUG=true bundle install\n    JARS_DEBUG=true gem install some_gem\n\nThe maven command line which gets printed needs maven-3.9.x and the\nruby DSL extension for maven:\n[https://github.com/takari/polyglot-maven#configuration](polyglot-maven\nconfiguration) where ```${maven.multiModuleProjectDirectory}``` is\nyour current directory.\n\n# Configuration\n\n\u003ctable border='1'\u003e\n\u003ctr\u003e\n\u003ctd\u003eENV\u003c/td\u003e\u003ctd\u003ejava system property\u003c/td\u003e\u003ctd\u003edefault\u003c/td\u003e\u003ctd\u003edescription\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ctt\u003eJARS_DEBUG\u003c/tt\u003e\u003c/td\u003e\u003ctd\u003ejars.debug\u003c/td\u003e\u003ctd\u003efalse\u003c/td\u003e\u003ctd\u003eif set to true it will produce lots of debug out (maven -X switch)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ctt\u003eJARS_VERBOSE\u003c/tt\u003e\u003c/td\u003e\u003ctd\u003ejars.verbose\u003c/td\u003e\u003ctd\u003efalse\u003c/td\u003e\u003ctd\u003eif set to true it will produce some extra output\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ctt\u003eJARS_HOME\u003c/tt\u003e\u003c/td\u003e\u003ctd\u003ejars.home\u003c/td\u003e\u003ctd\u003e$HOME/.m2/repository\u003c/td\u003e\u003ctd\u003efilesystem location where to store the jar files and some metadata\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ctt\u003eJARS_MAVEN_SETTINGS\u003c/tt\u003e\u003c/td\u003e\u003ctd\u003ejars.maven.settings\u003c/td\u003e\u003ctd\u003e$HOME/.m2/settings.xml\u003c/td\u003e\u003ctd\u003esetting.xml for maven to use\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ctt\u003eJARS_VENDOR\u003c/tt\u003e\u003c/td\u003e\u003ctd\u003ejars.vendor\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003eset to true means that the jars will be stored in JARS_HOME only\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ctt\u003eJARS_SKIP\u003c/tt\u003e\u003c/td\u003e\u003ctd\u003ejars.skip\u003c/td\u003e\u003ctd\u003etrue\u003c/td\u003e\u003ctd\u003edo **NOT** install jar dependencies at all\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n# Motivation\n\nJust today, I stumbled across [https://github.com/arrigonialberto86/ruby-band](https://github.com/arrigonialberto86/ruby-band) which uses jbundler to manage their JAR dependencies, which happens on the first 'require \"ruby-band\"'. There is no easy or formal way to find out which JARs are added to jruby-classloader.\n\nAnother issue was brought to my notice yesterday [https://github.com/hqmq/derelicte/issues/1](https://github.com/hqmq/derelicte/issues/1).\n\nOr the question of how to manage JRuby projects with maven [http://ruby.11.x6.nabble.com/Maven-dependency-management-td4996934.html](http://ruby.11.x6.nabble.com/Maven-dependency-management-td4996934.html)\n\nOr a few days ago an issue for rake-compile [https://github.com/luislavena/rake-compiler/issues/87](https://github.com/luislavena/rake-compiler/issues/87)\n\nWith JRuby 9000 it is the right time to get jar dependencies \"right\" - the current situation is like the time before bundler for gems.\n\n# Developing\n\nYou must have the latest ruby-maven installed in your local JRuby.\n\n./mvnw install will build the gem and run integration tests\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjar-dependencies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjruby%2Fjar-dependencies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjar-dependencies/lists"}