jar-dependencies 0.3.12 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +71 -71
- data/bin/lock_jars +6 -5
- data/jar-dependencies.gemspec +1 -0
- data/lib/jar_dependencies.rb +17 -4
- data/lib/jars/version.rb +1 -1
- metadata +30 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2a5716a45be706871dee379b8460a7262605db5
|
4
|
+
data.tar.gz: 05b060c6a93a43062308daae49a2957be4ac3765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6282cb6b2a56ef60f6110a47c0faecd95ce601a04691a4f2d244f5c073c9275b9612606f4b3793bee32b71222c809acc6088452b4dc1c4f338185d4977c9ab5b
|
7
|
+
data.tar.gz: ec8b9752bdaa207faa85dfcdf192d7a0bdedda927ecab72ec581705efea679edff1d2e9a4c8075c1682f68b897cb576ed367f8e14d03fc55ee80d43146671ce2
|
data/Readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# jar-dependencies
|
1
|
+
# jar-dependencies
|
2
2
|
|
3
3
|
* [![Build Status](https://secure.travis-ci.org/mkristian/jar-dependencies.svg)](http://travis-ci.org/mkristian/jar-dependencies)
|
4
4
|
* [![Code Climate](https://codeclimate.com/github/mkristian/jar-dependencies.svg)](https://codeclimate.com/github/mkristian/jar-dependencies)
|
@@ -6,141 +6,142 @@
|
|
6
6
|
add gem dependencies for jar files to ruby gems.
|
7
7
|
|
8
8
|
|
9
|
-
##
|
9
|
+
## Getting control back over your jar
|
10
10
|
|
11
11
|
jar dependencies are declared in the gemspec of the gem using the same notation
|
12
12
|
as <https://github.com/mkristian/jbundler>.
|
13
13
|
|
14
|
-
|
14
|
+
When using `require_jar` to load the jar into JRuby's classloader a version conflict
|
15
15
|
will be detected and only **ONE** jar gets loaded.
|
16
16
|
**jbundler** allows to select the version suitable for you application.
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
Most maven-artifacts do **NOT** use versions ranges but depend on a concrete version.
|
19
|
+
In such cases **jbundler** can always **overwrite** any such version.
|
20
20
|
|
21
21
|
|
22
|
-
##
|
22
|
+
## Vendoring your jars before packing the jar
|
23
23
|
|
24
|
-
|
24
|
+
Add the following to your *Rakefile*:
|
25
25
|
|
26
26
|
require 'jars/installer'
|
27
27
|
task :install_jars do
|
28
28
|
Jars::Installer.vendor_jars!
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
file **lib/my_gem_jars.rb
|
31
|
+
This will install (download) the dependent jars into **JARS_HOME** and create a
|
32
|
+
file **lib/my_gem_jars.rb**, which will be an enumeration of `require_jars`
|
33
33
|
statements to load all the jars.
|
34
|
-
|
34
|
+
The **vendor_jars** task will copy them into the **lib** directory of the gem.
|
35
35
|
|
36
|
-
|
36
|
+
The location where jars are cached is per default **$HOME/.m2/repository** the
|
37
37
|
same default as Maven uses to cache downloaded jar-artifacts.
|
38
|
-
|
38
|
+
It respects **$HOME/.m2/settings.xml** from Maven with mirror and other settings
|
39
39
|
or the environment variable **JARS_HOME**.
|
40
40
|
|
41
|
-
**IMPORTANT**:
|
42
|
-
of your gem.
|
41
|
+
**IMPORTANT**: Make sure that jar-dependencies is only a **development dependency**
|
42
|
+
of your gem. If it is a runtime dependency the require_jars file will be overwritten
|
43
43
|
during installation.
|
44
44
|
|
45
45
|
|
46
|
-
##
|
46
|
+
## Reduce the download and reuse the jars from maven local repository
|
47
47
|
|
48
|
-
|
49
|
-
them when you install the gem.
|
48
|
+
If you do not want to vendor jars into a gem then **jar-dependency** gem can vendor
|
49
|
+
them when you install the gem. In that case do not use
|
50
50
|
`Jars::JarInstaller.install_jars` from the above rake tasks.
|
51
51
|
|
52
|
-
**NOTE**:
|
52
|
+
**NOTE**: Recent JRuby comes with **jar-dependencies** as default gem, for older
|
53
53
|
versions for the feature to work you need to gem install **jar-dependencies** first
|
54
54
|
and for bundler need to use the **bundle-with-jars** command instead.
|
55
55
|
|
56
|
-
**IMPORTANT**:
|
56
|
+
**IMPORTANT**: Make sure that jar-dependencies is a **runtime dependency** of your
|
57
57
|
gem so the require_jars file will be overwritten during installation with the
|
58
58
|
"correct" versions of the jars.
|
59
59
|
|
60
60
|
|
61
|
-
##
|
61
|
+
## For development you do not need to vendor the jars at all
|
62
62
|
|
63
|
-
|
63
|
+
Set the environment variable
|
64
64
|
|
65
65
|
export JARS_VENDOR=false
|
66
66
|
|
67
|
-
|
68
|
-
`require_jar` statements.
|
69
|
-
maven local repository and
|
67
|
+
to tell the jar_installer not vendor any jars, but only create the file with the
|
68
|
+
`require_jar` statements. This `require_jars` method will find the jar inside the
|
69
|
+
maven local repository and load it from there.
|
70
70
|
|
71
71
|
|
72
|
-
##
|
72
|
+
## Some drawbacks
|
73
73
|
|
74
|
-
*
|
75
|
-
*
|
76
|
-
*
|
74
|
+
* First you need to install the jar-dependency gem with its development dependencies installed (then ruby-maven gets installed as well)
|
75
|
+
* Bundler does not install the jar-dependencies (unless JRuby adds the gem as default gem)
|
76
|
+
* You need ruby-maven doing the job of dependency resolution and downloading them. gems not part of <http://rubygems.org> will not work currently
|
77
77
|
|
78
78
|
|
79
|
-
##
|
79
|
+
## JARs other than from maven-central
|
80
80
|
|
81
|
-
|
81
|
+
By default all jars need to come from maven-central (<search.maven.org>), in order
|
82
82
|
to use jars from any other repo you need to add it into your Maven *settings.xml*
|
83
83
|
and configure it in a way that works without an interactive prompt (username +
|
84
84
|
passwords needs to be part of the settings.xml file).
|
85
85
|
|
86
|
-
**NOTE:**
|
86
|
+
**NOTE:** Gems depending on jars other then maven-central will **NOT** work when
|
87
87
|
they get published on rubygems.org since the user of those gems will not have the
|
88
88
|
right settings.xml to allow them to access the jar dependencies.
|
89
89
|
|
90
90
|
|
91
|
-
##
|
91
|
+
## Examples
|
92
92
|
|
93
|
-
|
93
|
+
An [example with rspec and all](example/Readme.md) walks you through setup and
|
94
94
|
shows how development works and shows what happens during installation.
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
the rake-compiler in
|
96
|
+
There are some more examples with the various [project setups for gems and application](examples/README.md).
|
97
|
+
This includes using proper Maven for the project or ruby-maven with rake or
|
98
|
+
the rake-compiler in conjunction with jar-dependencies.
|
99
99
|
|
100
|
-
#
|
100
|
+
# Lock down versions
|
101
101
|
|
102
|
-
|
102
|
+
Whenever there are version ranges for jar dependencies it is advisable to lock down the versions of dependencies.
|
103
|
+
For the jar dependencies inside the gemspec declaration this can be done with:
|
103
104
|
|
104
105
|
lock_jars
|
105
106
|
|
106
|
-
|
107
|
-
jar-dependencies.
|
107
|
+
This is also working in **any** project which uses a gem with
|
108
|
+
jar-dependencies. It also uses a Jarfile if present. See the [sinatra
|
108
109
|
application from the examples](examples/sinatra-app/having-jarfile-and-gems-with-jar-dependencies/).
|
109
110
|
|
110
|
-
|
111
|
+
This means for a project using bundler and jar-dependencies the setup is
|
111
112
|
|
112
113
|
bundle install
|
113
114
|
lock_jars
|
114
115
|
|
115
|
-
|
116
|
+
This will install both gems and jars for the project.
|
116
117
|
|
117
|
-
|
118
|
+
Update a specific version is done with (use only the artifact_id)
|
118
119
|
|
119
120
|
lock_jars --update slf4j-api
|
120
121
|
|
121
|
-
|
122
|
+
And look at the dependencies tree
|
122
123
|
|
123
124
|
lock_jars --tree
|
124
125
|
|
125
|
-
|
126
|
-
|
126
|
+
As ```lock_jars``` uses ruby-maven to resolve the jar dependencies.
|
127
|
+
Since jar-dependencies does not declare ruby-maven as runtime dependency
|
127
128
|
(you just not need ruby-maven during runtime only when you want to
|
128
129
|
setup the project it is needed) it is advicable to have it as
|
129
|
-
development dependency in
|
130
|
+
development dependency in your Gemfile.
|
130
131
|
|
131
|
-
#
|
132
|
+
# Proxy and mirror setup
|
132
133
|
|
133
|
-
|
134
|
+
Proxies 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.
|
134
135
|
|
135
|
-
|
136
|
+
As 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).
|
136
137
|
|
137
|
-
|
138
|
+
You 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.
|
138
139
|
|
139
|
-
jar-dependencies itself uses maven **only** for the jars and all gems are managed by
|
140
|
+
jar-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.
|
140
141
|
|
141
|
-
#
|
142
|
+
# Gradle, Maven, etc
|
142
143
|
|
143
|
-
|
144
|
+
For dependency management frameworks like gradle (via
|
144
145
|
jruby-gradle-plugin) or maven (via jruby-maven-plugins
|
145
146
|
or jruby9-maven-plugins) or probably ivy or sbt can use the gem
|
146
147
|
artifacts from a maven repository like
|
@@ -148,37 +149,36 @@ artifacts from a maven repository like
|
|
148
149
|
or
|
149
150
|
[rubygems.lasagna.io/proxy/maven/releases](http://rubygems.lasagna.io/proxy/maven/releases/).
|
150
151
|
|
151
|
-
|
152
|
+
Each of these tools (including jar-dependencies) does the dependency
|
152
153
|
resolution slightly different and in rare cases can produce different
|
153
|
-
outcomes.
|
154
|
+
outcomes. But overall each tool can manage both jars and gems and
|
154
155
|
their transitive dependencies.
|
155
156
|
|
156
|
-
|
157
|
+
Popular gems like jrjackson or nokogiri do not declare their jars in
|
157
158
|
the gemspec files and just load the bundle jars into jruby
|
158
159
|
classloader, can easily create problems as the jackson and
|
159
|
-
xalan/xerces libraries used by those gems are popular ones in the
|
160
|
+
xalan/xerces libraries used by those gems are popular ones in the Java world.
|
160
161
|
|
161
|
-
#
|
162
|
-
|
163
|
-
since maven is used under the hood it is possible to get more insight
|
164
|
-
what maven is doing. show the regualr maven output:
|
162
|
+
# Troubleshooting
|
165
163
|
|
164
|
+
Since maven is used under the hood it is possible to get more insight
|
165
|
+
what maven is doing. Show the regular maven output:
|
166
166
|
|
167
167
|
JARS_VERBOSE=true bundle install
|
168
168
|
JARS_VERBOSE=true gem install some_gem
|
169
169
|
|
170
|
-
|
170
|
+
Or, with maven debug enabled
|
171
171
|
|
172
172
|
JARS_DEBUG=true bundle install
|
173
173
|
JARS_DEBUG=true gem install some_gem
|
174
174
|
|
175
|
-
|
175
|
+
The maven command line which gets printed needs maven-3.3.x and the
|
176
176
|
ruby DSL extension for maven:
|
177
177
|
[https://github.com/takari/polyglot-maven#configuration](polyglot-maven
|
178
178
|
configuration) where ```${maven.multiModuleProjectDirectory}``` is
|
179
179
|
your current directory.
|
180
180
|
|
181
|
-
#
|
181
|
+
# Configuration
|
182
182
|
|
183
183
|
<table border='1'>
|
184
184
|
<tr>
|
@@ -204,15 +204,15 @@ your current directory.
|
|
204
204
|
</tr>
|
205
205
|
</table>
|
206
206
|
|
207
|
-
#
|
207
|
+
# Motivation
|
208
208
|
|
209
|
-
|
209
|
+
Just 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.
|
210
210
|
|
211
|
-
|
211
|
+
Another issue was brought to my notice yesterday [https://github.com/hqmq/derelicte/issues/1](https://github.com/hqmq/derelicte/issues/1).
|
212
212
|
|
213
|
-
|
213
|
+
Or 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)
|
214
214
|
|
215
|
-
|
215
|
+
Or 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)
|
216
216
|
|
217
|
-
|
217
|
+
With JRuby 9000 it is the right time to get jar dependencies "right" - the current situation is like the time before bundler for gems.
|
218
218
|
|
data/bin/lock_jars
CHANGED
@@ -5,11 +5,6 @@ options = {}
|
|
5
5
|
optparse = OptionParser.new do |opts|
|
6
6
|
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
|
7
7
|
|
8
|
-
opts.separator ''
|
9
|
-
opts.separator 'THIS IS A EXPERIMETAL FEATURE !!!'
|
10
|
-
opts.separator ''
|
11
|
-
opts.separator '* load jars "Jars.lock" from current working directory: `Jars.require_jars_lock!`'
|
12
|
-
opts.separator '* classpath features: see `Jars::Classpath'
|
13
8
|
opts.separator ''
|
14
9
|
opts.separator 'Options:'
|
15
10
|
opts.separator ''
|
@@ -42,6 +37,12 @@ optparse = OptionParser.new do |opts|
|
|
42
37
|
puts opts
|
43
38
|
exit
|
44
39
|
end
|
40
|
+
|
41
|
+
opts.separator ''
|
42
|
+
opts.separator 'THIS IS A EXPERIMETAL FEATURE !!!'
|
43
|
+
opts.separator ''
|
44
|
+
opts.separator '* load jars "Jars.lock" from current working directory: `Jars.require_jars_lock!`'
|
45
|
+
opts.separator '* classpath features: see `Jars::Classpath'
|
45
46
|
end
|
46
47
|
optparse.parse!
|
47
48
|
|
data/jar-dependencies.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.description = 'manage jar dependencies for gems and keep track which jar was already loaded using maven artifact coordinates. it warns on version conflicts and loads only ONE jar assuming the first one is compatible to the second one otherwise your project needs to lock down the right version by providing a Jars.lock file.'
|
27
27
|
|
28
28
|
s.add_development_dependency 'minitest', '~> 5.3'
|
29
|
+
s.add_development_dependency 'pry'
|
29
30
|
s.add_development_dependency 'rake', '~> 10.2'
|
30
31
|
RUBY_MAVEN_VERSION = '~> 3.3.11'.freeze
|
31
32
|
s.add_development_dependency 'ruby-maven', RUBY_MAVEN_VERSION
|
data/lib/jar_dependencies.rb
CHANGED
@@ -45,6 +45,8 @@ module Jars
|
|
45
45
|
DEBUG = 'JARS_DEBUG'.freeze
|
46
46
|
# vendor jars inside gem when installing gem
|
47
47
|
VENDOR = 'JARS_VENDOR'.freeze
|
48
|
+
# string used when the version is unknown
|
49
|
+
UNKNOWN = 'unknown'
|
48
50
|
end
|
49
51
|
|
50
52
|
autoload :MavenSettings, 'jars/maven_settings'
|
@@ -136,7 +138,11 @@ module Jars
|
|
136
138
|
|
137
139
|
def jars_lock_from_class_loader
|
138
140
|
if to_prop(LOCK).nil? && defined?(JRUBY_VERSION)
|
139
|
-
JRuby.
|
141
|
+
if JRuby::Util.respond_to?(:class_loader_resources)
|
142
|
+
JRuby::Util.class_loader_resources('Jars.lock')
|
143
|
+
else; require 'jruby'
|
144
|
+
JRuby.runtime.jruby_class_loader.get_resources('Jars.lock').collect(&:to_s)
|
145
|
+
end
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
@@ -247,8 +253,14 @@ module Jars
|
|
247
253
|
end
|
248
254
|
end
|
249
255
|
|
250
|
-
def require_jar(group_id, artifact_id, *classifier_version)
|
256
|
+
def require_jar(group_id, artifact_id, *classifier_version, &block)
|
251
257
|
require_jars_lock unless skip_lock?
|
258
|
+
if classifier_version.empty? && block_given?
|
259
|
+
classifier_version = [block.call].compact
|
260
|
+
if classifier_version.empty?
|
261
|
+
return mark_as_required(group_id, artifact_id, UNKNOWN) || false
|
262
|
+
end
|
263
|
+
end
|
252
264
|
require_jar_with_block(group_id, artifact_id, *classifier_version) do |gid, aid, version, classifier|
|
253
265
|
do_require(gid, aid, version, classifier)
|
254
266
|
end
|
@@ -346,10 +358,11 @@ module Jars
|
|
346
358
|
end # class << self
|
347
359
|
end
|
348
360
|
|
349
|
-
def require_jar(*args)
|
361
|
+
def require_jar(*args, &block)
|
350
362
|
return nil unless Jars.require?
|
351
|
-
result = Jars.require_jar(*args)
|
363
|
+
result = Jars.require_jar(*args, &block)
|
352
364
|
if result.is_a? String
|
365
|
+
args << (block.call || Jars::UNKNOWN) if args.size == 2 && block_given?
|
353
366
|
Jars.warn { "--- jar coordinate #{args[0..-2].join(':')} already loaded with version #{result} - omit version #{args[-1]}" }
|
354
367
|
Jars.debug { " try to load from #{caller.join("\n\t")}" }
|
355
368
|
return false
|
data/lib/jars/version.rb
CHANGED
metadata
CHANGED
@@ -1,58 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jar-dependencies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian meier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '5.3'
|
14
19
|
name: minitest
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
15
22
|
version_requirements: !ruby/object:Gem::Requirement
|
16
23
|
requirements:
|
17
24
|
- - "~>"
|
18
25
|
- !ruby/object:Gem::Version
|
19
26
|
version: '5.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
20
28
|
requirement: !ruby/object:Gem::Requirement
|
21
29
|
requirements:
|
22
|
-
- - "
|
30
|
+
- - ">="
|
23
31
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
32
|
+
version: '0'
|
33
|
+
name: pry
|
25
34
|
prerelease: false
|
26
35
|
type: :development
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
36
|
version_requirements: !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
|
-
- - "
|
38
|
+
- - ">="
|
32
39
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
34
42
|
requirement: !ruby/object:Gem::Requirement
|
35
43
|
requirements:
|
36
44
|
- - "~>"
|
37
45
|
- !ruby/object:Gem::Version
|
38
46
|
version: '10.2'
|
47
|
+
name: rake
|
39
48
|
prerelease: false
|
40
49
|
type: :development
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: ruby-maven
|
43
50
|
version_requirements: !ruby/object:Gem::Requirement
|
44
51
|
requirements:
|
45
52
|
- - "~>"
|
46
53
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
54
|
+
version: '10.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
48
56
|
requirement: !ruby/object:Gem::Requirement
|
49
57
|
requirements:
|
50
58
|
- - "~>"
|
51
59
|
- !ruby/object:Gem::Version
|
52
60
|
version: 3.3.11
|
61
|
+
name: ruby-maven
|
53
62
|
prerelease: false
|
54
63
|
type: :development
|
55
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.3.11
|
69
|
+
description: manage jar dependencies for gems and keep track which jar was already
|
70
|
+
loaded using maven artifact coordinates. it warns on version conflicts and loads
|
71
|
+
only ONE jar assuming the first one is compatible to the second one otherwise your
|
72
|
+
project needs to lock down the right version by providing a Jars.lock file.
|
56
73
|
email:
|
57
74
|
- mkristian@web.de
|
58
75
|
executables:
|
@@ -116,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
133
|
version: '0'
|
117
134
|
requirements: []
|
118
135
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.6.14.1
|
120
137
|
signing_key:
|
121
138
|
specification_version: 4
|
122
139
|
summary: manage jar dependencies for gems
|