Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • rubygems/package_task.rb



Class/Module Index [+]



Create a package based upon a Gem::Specification. Gem packages, as well as zip files and tar/gzipped packages can be produced by this task.

In addition to the Rake targets generated by Rake::PackageTask, a Gem::PackageTask will also generate the following tasks:


Create a RubyGems package with the given name and version.

Example using a Gem::Specification:

require 'rubygems'
require 'rubygems/package_task'

spec = Gem::Specification.new do |s|
  s.platform = Gem::Platform::RUBY
  s.summary = "Ruby based make-like utility."
  s.name = 'rake'
  s.version = PKG_VERSION
  s.requirements << 'none'
  s.require_path = 'lib'
  s.autorequire = 'rake'
  s.files = PKG_FILES
  s.description = <<-EOF
Rake is a Make-like program implemented in Ruby. Tasks
and dependencies are specified in standard Ruby syntax.

Gem::PackageTask.new(spec) do |pkg|
  pkg.need_zip = true
  pkg.need_tar = true



Ruby Gem::Specification containing the metadata for this package. The name, version and package_files are automatically determined from the gemspec and don’t need to be explicitly provided.

Public Class Methods

new(gem_spec) click to toggle source

Create a Gem Package task library. Automatically define the gem if a block is given. If no block is supplied, then define needs to be called to define the task.

               # File rubygems/package_task.rb, line 79
def initialize(gem_spec)
  init gem_spec
  yield self if block_given?
  define if block_given?

Public Instance Methods

define() click to toggle source

Create the Rake tasks and actions specified by this Gem::PackageTask. (define is automatically called if a block is given to new).

               # File rubygems/package_task.rb, line 98
def define

  task :package => [:gem]

  gem_file = File.basename gem_spec.cache_file
  gem_path = File.join package_dir, gem_file
  gem_dir  = File.join package_dir, gem_spec.full_name

  desc "Build the gem file #{gem_file}"
  task :gem => [gem_path]

  trace = Rake.application.options.trace
  Gem.configuration.verbose = trace

  file gem_path => [package_dir, gem_dir] + @gem_spec.files do
    chdir(gem_dir) do
      when_writing "Creating #{gem_spec.file_name}" do
        verbose trace do
          mv gem_file, '..'
init(gem) click to toggle source

Initialization tasks without the “yield self” or define operations.

               # File rubygems/package_task.rb, line 88
def init(gem)
  super gem.full_name, :noversion
  @gem_spec = gem
  @package_files += gem_spec.files if gem_spec.files

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.