最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby - run bundler on multiple gemspec files in one run - Stack Overflow

programmeradmin0浏览0评论

I have many small projects on the go. Most of the configuration of these is the same. But usually there is an extra gem I need for a particular project. I am currently maintaining the Gemfile manually.

On the python side of things, I created a set of xx_requirement.txt files that hold the common pip modules and then use a requirement.txt file to load the unique ones.

I'd like to do the same for ruby/bundler. For example, have one gemfile hold common gems for all projects, and then use another gemfile to hold other gems specifically for ruby apps or a gemfile to that holds gems for ruby modules. And a last gemfile that holds unique gems for that that project.

  • OS: Ubuntu 24.04.1 LTS
  • bundler: Bundler version 2.6.2

I have a .bundle/config file in each project:

---
BUNDLE_PATH: "venv"

When I load the current Gemfile it works perfectly:

bundle install --gemfile=Gemfile

current Gemfile

# frozen_string_literal: true

source ''
#gem 'minitest'
#gem 'minitest-reporters'
gem 'os'
gem 'rake'
<snip>
<gem 'yard'

I tried creating a gems_app.gemspec file in a sub directory (a git submodule):

# frozen_string_literal: true

source ''
gem 'minitest'
gem 'minitest-reporters'

just to see if I could load minitest by itself. It didn't work.

bundle install --gemfile=Gemfile
bundle install --gemfile=tools/install/gems_app.gemspec

output:

Fetching gem metadata from /...
Resolving dependencies...
Fetching ansi 1.5.0
Fetching builder 3.3.0
Fetching minitest 5.25.4
Fetching ruby-progressbar 1.13.0

Retrying download gem from / due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.2.0/cache/ansi-1.5.0.gem`. It is likely that you need to grant write permissions for that path.

<snip similar warnings from here>

Not sure, but it looks like it's not reading the config file?

Any tips or hints on what to try next would be greatly appreciated!

Update: just tried this and it worked! Sort of

bundle install --gemfile=Gemfile
bundle install --path ./venv --gemfile=tools/install/gems_app.gemspec

There is a warning though:

[DEPRECATED] The `--path` flag is deprecated because it relies on
being remembered across bundler invocations, which bundler will no
longer do in future versions. Instead please use `bundle config set
path './venv'`, and stop using this flag

also it creates these new files: ''' tools/install/.bundle/ tools/install/gems_app.gemspec.lock ''' which should be using the existing .bundle and .lock files instead.

Note that .6/man/bundle-config.1.html does not indicate that --path is deprecated.

I have many small projects on the go. Most of the configuration of these is the same. But usually there is an extra gem I need for a particular project. I am currently maintaining the Gemfile manually.

On the python side of things, I created a set of xx_requirement.txt files that hold the common pip modules and then use a requirement.txt file to load the unique ones.

I'd like to do the same for ruby/bundler. For example, have one gemfile hold common gems for all projects, and then use another gemfile to hold other gems specifically for ruby apps or a gemfile to that holds gems for ruby modules. And a last gemfile that holds unique gems for that that project.

  • OS: Ubuntu 24.04.1 LTS
  • bundler: Bundler version 2.6.2

I have a .bundle/config file in each project:

---
BUNDLE_PATH: "venv"

When I load the current Gemfile it works perfectly:

bundle install --gemfile=Gemfile

current Gemfile

# frozen_string_literal: true

source 'https://rubygems.'
#gem 'minitest'
#gem 'minitest-reporters'
gem 'os'
gem 'rake'
<snip>
<gem 'yard'

I tried creating a gems_app.gemspec file in a sub directory (a git submodule):

# frozen_string_literal: true

source 'https://rubygems.'
gem 'minitest'
gem 'minitest-reporters'

just to see if I could load minitest by itself. It didn't work.

bundle install --gemfile=Gemfile
bundle install --gemfile=tools/install/gems_app.gemspec

output:

Fetching gem metadata from https://rubygems./...
Resolving dependencies...
Fetching ansi 1.5.0
Fetching builder 3.3.0
Fetching minitest 5.25.4
Fetching ruby-progressbar 1.13.0

Retrying download gem from https://rubygems./ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.2.0/cache/ansi-1.5.0.gem`. It is likely that you need to grant write permissions for that path.

<snip similar warnings from here>

Not sure, but it looks like it's not reading the config file?

Any tips or hints on what to try next would be greatly appreciated!

Update: just tried this and it worked! Sort of

bundle install --gemfile=Gemfile
bundle install --path ./venv --gemfile=tools/install/gems_app.gemspec

There is a warning though:

[DEPRECATED] The `--path` flag is deprecated because it relies on
being remembered across bundler invocations, which bundler will no
longer do in future versions. Instead please use `bundle config set
path './venv'`, and stop using this flag

also it creates these new files: ''' tools/install/.bundle/ tools/install/gems_app.gemspec.lock ''' which should be using the existing .bundle and .lock files instead.

Note that https://bundler.io/v2.6/man/bundle-config.1.html does not indicate that --path is deprecated.

Share Improve this question edited Feb 1 at 2:55 JohnA asked Feb 1 at 1:57 JohnAJohnA 8492 gold badges10 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can make a gem with common dependencies and include it into your current project Gemfile:

# Gemfile

source "https://rubygems."

gem "common", path: "./common"

gem "os"
gem "rake"

:path, :git, :github etc. will work:
https://bundler.io/v2.6/man/gemfile.5.html#SOURCE

common gem is just one file:

# common/common.gemspec

Gem::Specification.new do |spec|
  spec.name = "common"
  spec.version = "0.0.1"
  spec.authors = ["Alex"]
  spec.summary = "Write a short summary, because RubyGems requires one."
  spec.required_ruby_version = ">= 3.0.0"

  spec.add_dependency "minitest"
  spec.add_dependency "minitest-reporters"
end

Test it:

# --path is deprecated, actual config is not
$ bundle config set --local path vendor/bundle
$ cat .bundle/config
---
BUNDLE_PATH: "vendor/bundle"

# `bundle install --gemfile=Gemfile` is a long way of saying:
$ bundle
Fetching gem metadata from https://rubygems./....
Resolving dependencies...
Fetching rake 13.2.1
Installing rake 13.2.1
Fetching ansi 1.5.0
Fetching builder 3.3.0
Fetching minitest 5.25.4
Fetching ruby-progressbar 1.13.0
Installing ansi 1.5.0
Fetching os 1.1.4
Installing builder 3.3.0
Installing minitest 5.25.4
Installing ruby-progressbar 1.13.0
Installing os 1.1.4
Fetching minitest-reporters 1.7.1
Installing minitest-reporters 1.7.1
Bundle complete! 3 Gemfile dependencies, 9 gems now installed.
Bundled gems are installed into `./vendor/bundle`
发布评论

评论列表(0)

  1. 暂无评论