Index: lib/buildr/packaging/artifact.rb
===================================================================
--- lib/buildr/packaging/artifact.rb	(revision 883432)
+++ lib/buildr/packaging/artifact.rb	Thu Feb 11 12:19:34 CET 2010
@@ -153,15 +153,14 @@
     # In the third form, uses a hash with the options :url, :username, :password,
     # and :permissions. All but :url are optional.
     def upload(upload_to = nil)
-      # Where do we release to?
+      upload_task(upload_to).invoke
+    end
+
+    def upload_task(upload_to = nil)
       upload_to ||= Buildr.repositories.release_to
       upload_to = { :url=>upload_to } unless Hash === upload_to
       raise ArgumentError, 'Don\'t know where to upload, perhaps you forgot to set repositories.release_to' unless upload_to[:url]
-      invoke # Make sure we exist.
 
-      # Upload POM ahead of package, so we don't fail and find POM-less package (the horror!)
-      pom.upload(upload_to) if pom && pom != self
-
       # Set the upload URI, including mandatory slash (we expect it to be the base directory).
       # Username/password may be part of URI, or separate entities.
       uri = URI.parse(upload_to[:url].clone)
@@ -169,11 +168,20 @@
       uri.user = upload_to[:username] if upload_to[:username]
       uri.password = upload_to[:password] if upload_to[:password]
 
+      path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}"
+
+      unless task = Buildr.application.lookup(uri+path)
+        deps = [self]
+        deps << pom.upload_task( upload_to ) if pom && pom != self
+
+        task = Rake::Task.define_task uri + path => deps do
-      # Upload artifact relative to base URL, need to create path before uploading.
-      info "Deploying #{to_spec}"
+          # Upload artifact relative to base URL, need to create path before uploading.
+          info "Deploying #{to_spec}"
-      path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}"
-      URI.upload uri + path, name, :permissions=>upload_to[:permissions]
-    end
+          URI.upload uri + path, name, :permissions=>upload_to[:permissions]
+        end
+      end
+      task
+    end
 
   protected
 
@@ -737,14 +745,12 @@
   #   upload artifact('group:id:jar:1.0').from('some_jar.jar')
   #   $ buildr upload
   def upload(*args, &block)
-    artifacts = artifacts(args)
+    upload_artifacts_tasks = artifacts(args).map { |artifact| artifact.upload_task }
     raise ArgumentError, 'This method can only upload artifacts' unless artifacts.all? { |f| f.respond_to?(:to_spec) }
     task('upload').tap do |task|
       task.enhance &block if block
-      task.enhance artifacts do
-        artifacts.each { |artifact| artifact.upload }
+      task.enhance upload_artifacts_tasks
-      end
-    end
+    end
+  end
-  end
 
 end
Index: lib/buildr/packaging/package.rb
===================================================================
--- lib/buildr/packaging/package.rb	(revision 902243)
+++ lib/buildr/packaging/package.rb	Thu Feb 11 12:06:34 CET 2010
@@ -192,7 +192,7 @@
 
         task('install')   { package.install if package.respond_to?(:install) }
         task('uninstall') { package.uninstall if package.respond_to?(:uninstall) }
-        task('upload')    { package.upload if package.respond_to?(:upload) }
+        task('upload' => package.upload_task ) if package.respond_to?(:upload_task)
 
         packages << package
       end
