Skip to content

Provide a way to force specific traits #587

@headius

Description

@headius

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:

def self.detect?
Traits::Rails.detect? || Traits::Rack.detect?
end

And the "jar" trait deactivates if the "war" trait activates:

def self.detect?
!War.detect?
end

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions