Upload to repository

Olivier's Avatar

Olivier

11 Jun, 2012 07:02 PM

Hi
I'm new to Gradle (and GradleFx) and so far I'm liking it. I now trying to upload the result of compilation to my local repository (maven?, ivy? gradle? I'm not sure). Basically, I want to compile this library project, install/upload it to my local repository so my application (swf) project can use it as a dependency. I don't want to use it as a subproject, because it's not.

Any example on how to do this? The Gradle documentation is farely Java based and I'm not sure how stuff translates to GradleFx.

Also, what does the publish task do?

Thanks!

  1. Support Staff 1 Posted by Yennick Trevels on 11 Jun, 2012 08:12 PM

    Yennick Trevels's Avatar

    You can do this by adding the following code to your build file:

    userHome = System.getProperty("user.home")
    
    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "file://{userHome}/.m2/repository/") 
            }
        }
    }
    

    Then you can install them to your local maven repository (in your user directory) with "gradle uploadArchives"

    The upload task just copies the content in the build directory to a publish directory. Actually it doesn't do much useful, so we probably should find a better cause for this task.

  2. 2 Posted by Olivier on 11 Jun, 2012 08:31 PM

    Olivier's Avatar

    I've tried this snippet from the other post, but it doesn't work. I get this error :

    [ant:null] Error reading settings file 'C:\Users\ogroulx\AppData\Local\Temp\gradle_empty_settings3215823816589171383.xml' - ignoring. Error was: C:\Users\ogroulx\AppData\Local\Temp\gradle_empty_settings3215823816589171383.xml (The file was not found)

    And nothing is copied to the maven repo.

    Also, mavenDeployer require apply plugin : 'maven' to work. In fact, here's my configuration :

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath group: 'org.gradlefx', name: 'gradlefx', version: '0.5'
        }
    }
    
    apply plugin: 'gradlefx'
    apply plugin: 'maven'
    
    type = 'swc'
    
    srcDirs = [
        'src'
    ]
    
    
    dependencies {
        external files("lib")
    }
    
    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "file://C:/Users/ogroulx/.m2/repository/") 
            }
        }
    }
    

    Am I missing something?

  3. Support Staff 3 Posted by Yennick Trevels on 11 Jun, 2012 08:57 PM

    Yennick Trevels's Avatar

    mmm, haven't encountered this one before, but I tried it on one of my sample projects and it's giving the same error now. Looks like someone else is getting the same error on the Gradle forums (not GradleFx related): http://forums.gradle.org/gradle/topics/_error_reading_settings_file...

    I'll post something in that thread, maybe Peter Niederwieser knows a solution to this problem.

  4. Support Staff 4 Posted by Maxime Cowez on 12 Jun, 2012 08:31 AM

    Maxime Cowez's Avatar

    Perhaps you could give it another try with Gradle 1.0 which was released earlier today?

  5. Support Staff 5 Posted by Yennick Trevels on 12 Jun, 2012 08:40 AM

    Yennick Trevels's Avatar

    I'll try to track it down this evening by looking from which Gradle version it has been going wrong.
    Maxime, aren't you using this same method to upload the artifacts to your local maven repo? and is it still working for you?

  6. Support Staff 6 Posted by Maxime Cowez on 12 Jun, 2012 09:12 AM

    Maxime Cowez's Avatar

    Yep, still working fine here with the development build (which should be the same as the 0.5 release)


    Gradle 1.0-rc-3

    Gradle build time: Sunday, 29 April 2012 23:51:52 o'clock UTC
    Groovy: 1.8.6
    Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
    Ivy: 2.2.0
    JVM: 1.7.0_02 (Oracle Corporation 22.0-b10)
    OS: Windows 7 6.1 x86

  7. 7 Posted by Olivier on 12 Jun, 2012 12:22 PM

    Olivier's Avatar

    I'll try with Gradle 1.0 today. The only difference with Max I think is that I'm using Windows 7 64 bit.

  8. Support Staff 8 Posted by Yennick Trevels on 12 Jun, 2012 12:25 PM

    Yennick Trevels's Avatar

    mmm, I'm also using Windows 7 64 bit, so that could very well be it.

  9. Support Staff 9 Posted by Maxime Cowez on 12 Jun, 2012 12:45 PM

    Maxime Cowez's Avatar

    Yennick, your output in the Gradle forum says Win7 x86

  10. 10 Posted by Olivier on 12 Jun, 2012 01:56 PM

    Olivier's Avatar

    Nope. Even with Gradle 1.0, the error still occur. From the Gradle forum, bjansen has replied that it's just a way of saying that the artifact doesn't exist on the file system. I'm not sure what to do with that.

  11. Support Staff 11 Posted by Yennick Trevels on 12 Jun, 2012 08:24 PM

    Yennick Trevels's Avatar

    I think I see what's going wrong. The uploadArchives task doesn't depend anymore on the compile task (which is implemented by GradleFx, but is a general name used by many plugins to compile something), so it doesn't automatically execute the compile task, which causes the artifact not being added.

    Try this piece of code out:

    afterEvaluate {
        uploadArchives {
            dependsOn compile
             repositories {
                mavenDeployer {
                    repository(url: "file://{userHome}/.m2/repository/") 
                }
            }
    }
    }
    

    The afterEvaluate statement is needed because the compile task is only added in a later phase, so after the evaluation phase of Gradle.
    Then I've defined a task dependency to the compile task, which should make the compile task to execute before the uploadArchives task is being executed.

    Maybe this isn't the most optimal solution, so I'm trying to find a better solution, but this should get you going :)

  12. 12 Posted by Olivier on 12 Jun, 2012 10:49 PM

    Olivier's Avatar

    Alright, getting somewhere. The maven plugin was complaining about the groupId being empty. I've added a group and a version property to the build config and it worked! Thanks!

  13. Support Staff 13 Posted by Maxime Cowez on 13 Jun, 2012 08:53 AM

    Maxime Cowez's Avatar

    So why did it work for me? My guess is because I had executed gradle compile manually prior to executing gradle upload.

  14. Yennick Trevels closed this discussion on 15 Aug, 2012 02:04 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac