-
Notifications
You must be signed in to change notification settings - Fork 21
declare jars inside gemspec
the notation of the jar or pom dependencies inside a gemspec file is the same as with JBundler: https://github.com/torquebox/maven-tools/wiki/Jarfile#jarpom-dependencies
this declaration goes into the requirements part of the Gem::Specification
Gem::Specification.new do |s|
s.requirements << "jar org.bouncycastle:bcpkix-jdk15on, 1.50"
s.requirements << "jar 'org.bouncycastle:bcprov-jdk15on', '1.50'"
end
note: the parentheses are optional.
it is also possible to add a maven scope to it
Gem::Specification.new do |s|
s.requirements << "jar org.bouncycastle:bcpkix-jdk15on, 1.50, :scope => :provided"
s.requirements << "jar 'org.bouncycastle:bcprov-jdk15on', '1.50', :scope => :test"
end
in case you do not want a jar-dependencies gem as runtime dependency you still can use the jar declaration inside the gemspec file and use the jar-dependencies feature of "tracking" the versions of the required jars.
excerpt from https://github.com/jruby/jruby-openssl/blob/master/jruby-openssl.gemspec
Gem::Specification.new do |s|
s.requirements << "jar org.bouncycastle:bcpkix-jdk15on, #{Jopenssl::Version::BOUNCY_CASTLE_VERSION}"
s.requirements << "jar org.bouncycastle:bcprov-jdk15on, #{Jopenssl::Version::BOUNCY_CASTLE_VERSION}"
s.add_development_dependency 'jar-dependencies', '0.0.4'
endand the part which loads the jars looks like this (https://github.com/jruby/jruby-openssl/blob/master/lib/jopenssl/load.rb#L6
begin
# if we have jar-dependencies we let it track the jars
require 'jar-dependencies'
require_jar( 'org.bouncycastle', 'bcpkix-jdk15on', Jopenssl::Version::BOUNCY_CASTLE_VERSION )
require_jar( 'org.bouncycastle', 'bcprov-jdk15on', Jopenssl::Version::BOUNCY_CASTLE_VERSION )
rescue LoadError
require "org/bouncycastle/bcpkix-jdk15on/#{Jopenssl::Version::BOUNCY_CASTLE_VERSION}/bcpkix-jdk15on-#{Jopenssl::Version::BOUNCY_CASTLE_VERSION}.jar"
require "org/bouncycastle/bcprov-jdk15on/#{Jopenssl::Version::BOUNCY_CASTLE_VERSION}/bcprov-jdk15on-#{Jopenssl::Version::BOUNCY_CASTLE_VERSION}.jar"
endthere is real need to leave out the jar-dependencies gem, then the above examples will look like this:
Gem::Specification.new do |s|
s.requirements << "jar org.bouncycastle:bcpkix-jdk15on, 1.50"
s.requirements << "jar org.bouncycastle:bcprov-jdk15on, 1.50"
s.add_runtime_dependency 'jar-dependencies', '0.0.8'
endand the loading code
require 'jar-dependencies'
require_jar( 'org.bouncycastle', 'bcpkix-jdk15on', '1.50' )
require_jar( 'org.bouncycastle', 'bcprov-jdk15on', '1.50' )the above example are simple example since there are no transitive dependencies of those embedded jars.