ruby/ruby · error · GemfileError

Two gemspec development dependencies have conflicting requir

Error message

Two gemspec development dependencies have conflicting requirements on the same gem: #{dep} and #{current}

What it means

Same merging path as the Gemfile/gemspec conflict, but here BOTH conflicting requirements come from gemspec development dependencies (lib/bundler/dsl.rb:347): the parsed gemspec ends up with two development dependency entries for one gem whose PubGrub ranges do not intersect, and neither is a Gemfile dep, so the GemfileError names the two Dependency objects directly. Bundler refuses to pick between contradictory constraints inside a single gemspec.

Source

Thrown at lib/bundler/dsl.rb:347

        if current.requirement != dep.requirement
          current_requirement_open = current.requirements_list.include?(">= 0")

          gemspec_dep = [dep, current].find(&:gemspec_dev_dep?)
          if gemspec_dep
            require_relative "vendored_pub_grub"

            current_gemspec_range = Gem::PubGrub::RubyGems.requirement_to_range(current.requirement)
            next_gemspec_range = Gem::PubGrub::RubyGems.requirement_to_range(dep.requirement)

            if current_gemspec_range.intersects?(next_gemspec_range)
              dep = Dependency.new(name, current.requirement.as_list + dep.requirement.as_list, options)
            else
              gemfile_dep = [dep, current].find(&:gemfile_dep?)

              if gemfile_dep
                raise GemfileError, "The #{name} dependency has conflicting requirements in Gemfile (#{gemfile_dep.requirement}) and gemspec (#{gemspec_dep.requirement})"
              else
                raise GemfileError, "Two gemspec development dependencies have conflicting requirements on the same gem: #{dep} and #{current}"
              end
            end
          else
            update_prompt = ""

            if File.basename(@gemfile) == Injector::INJECTED_GEMS
              if dep.requirements_list.include?(">= 0") && !current_requirement_open
                update_prompt = ". Gem already added"
              else
                update_prompt = ". If you want to update the gem version, run `bundle update #{name}`"

                update_prompt += ". You may also need to change the version requirement specified in the Gemfile if it's too restrictive." unless current_requirement_open
              end
            end

            raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \
                           "You specified: #{name} (#{current.requirement}) and #{name} (#{dep.requirement})" \
                           "#{update_prompt}"

View on GitHub (pinned to 0e5b888e1c)

Solutions

  1. Grep the gemspec for the gem name shown in the message and delete the stale add_development_dependency line
  2. If both lines must stay (conditional blocks), make their requirement ranges intersect
  3. Run `gem build yourgem.gemspec` or `bundle install` again to confirm the gemspec now parses to a single consistent requirement

Example fix

# before (mygem.gemspec)
spec.add_development_dependency "rspec", "~> 3.12"
spec.add_development_dependency "rspec", "~> 4.0" # conflicting

# after
spec.add_development_dependency "rspec", "~> 3.12"
Defensive patterns

Strategy: validation

Validate before calling

# Fail fast when a gemspec declares the same dev gem twice
deps = {}
spec = Gem::Specification.load("mygem.gemspec")
spec.development_dependencies.map(&:name).tally.each do |name, count|
  abort "gemspec declares #{name} #{count} times" if count > 1
end

Prevention

When it happens

Trigger: One .gemspec containing two `spec.add_development_dependency "rake", ...` calls with disjoint ranges (e.g. ">= 13" and "< 13"), typically after editing a version and forgetting the older line; also gemspecs generated by concatenating conditionals that both add the same gem differently.

Common situations: Gem under active development where a dev-tool version was changed by adding a new add_development_dependency instead of editing the existing one; gems with platform-conditional gemspec blocks each declaring the same dev dep with different pins.

Related errors


AI-assisted analysis of ruby/ruby@0e5b888e1c (2026-08-21). Data as JSON: /api/errors/a8a1b1e34a26c702. Report an issue: GitHub.