Provide a way to force specific traits
I was experimenting with warbling a Sidekiq jar but because it had Rails and Rack in its dependencies the "war" trait activated automatically.
Currently, the "war" trait activates if it detects either Rails or Rack:
https://github.com/jruby/warbler/blob/ef819a71290384aefb5e21f1df92212ea9615d80/lib/warbler/traits/war.rb#L20-L22
And the "jar" trait deactivates if the "war" trait activates:
https://github.com/jruby/warbler/blob/085c7830a47d1a0a444a4df1e8522911349acc0f/lib/warbler/traits/jar.rb#L19-L21
But Sidekiq is server that runs from the command-line, so I was forced to manually disable those other traits:
diff -rU 5 ../warbler/lib/warbler/traits/rack.rb ../jruby/lib/ruby/gems/shared/gems/warbler-2.1.0/lib/warbler/traits/rack.rb
--- ../warbler/lib/warbler/traits/rack.rb 2025-10-01 10:24:06
+++ ../jruby/lib/ruby/gems/shared/gems/warbler-2.1.0/lib/warbler/traits/rack.rb 2025-10-22 14:47:25
@@ -10,11 +10,11 @@
# The Rack trait adds config.ru to a Rack-based war project.
class Rack
include Trait
def self.detect?
- !Rails.detect? && (File.exist?("config.ru") || !Dir['*/config.ru'].empty?)
+ false #!Rails.detect? && (File.exist?("config.ru") || !Dir['*/config.ru'].empty?)
end
def self.requirements
[ Traits::War ]
end
diff -rU 5 ../warbler/lib/warbler/traits/war.rb ../jruby/lib/ruby/gems/shared/gems/warbler-2.1.0/lib/warbler/traits/war.rb
--- ../warbler/lib/warbler/traits/war.rb 2025-10-01 10:24:06
+++ ../jruby/lib/ruby/gems/shared/gems/warbler-2.1.0/lib/warbler/traits/war.rb 2025-10-22 14:44:12
@@ -16,11 +16,11 @@
include PathmapHelper
DEFAULT_GEM_PATH = '/WEB-INF/gems'
def self.detect?
- Traits::Rails.detect? || Traits::Rack.detect?
+ false #Traits::Rails.detect? || Traits::Rack.detect?
end
def before_configure
config.gem_path = DEFAULT_GEM_PATH
config.pathmaps = default_pathmaps
I am not an expert at Rake internals, so perhaps there's another way to disable this, but it seems not because it autodetects all traits and activates whatever is "detected".
I think you either were supposed to be able to, or used to be able to do so with config.traits = [Warbler::Traits::Jar] etc based on the comment at
https://github.com/jruby/warbler/blob/0a1f579b395ab85c2f9789973933cf5f892d5ef7/lib/warbler/config.rb#L31-L34
However unfortunately as the code is the traits start messing with the config in their before_configure blocks based on the auto-detected list before the user-supplied configuration block in config/warble.rb is executed, and so they seem effectively locked in.