On 16 April 2013 08:07, Steve Ebersole <st...@hibernate.org> wrote:

> Ah, right. The problem is that settings.xml does not contain urls. It
> matches based on a "server id" from the pom.
>
> I leveraged that in the current code by naming the repos in the Gradle
> build file. E.g.:
>
>    uploadArchives {
>       repositories.mavenDeployer {
>          ...
>          repository(id: "jboss-releases-repository", url: "
> https://repository.jboss.org/**nexus/service/local/staging/**
> deploy/maven2/<https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/>
> ")
>          snapshotRepository(id: "jboss-snapshots-repository", url: "
> https://repository.jboss.org/**nexus/content/repositories/**snapshots<https://repository.jboss.org/nexus/content/repositories/snapshots>
> ")
>       }
>    }
>
> As you can see, I use the id element of those repository definitions to be
> the link.
>
> However, there does not see to be any such notion on the new API
> (MavenArtifactRepository does not expose id).
>

> So, as far as I can tell I will not be able port this functionality to the
> new publishing API.  Unless I am missing something (very possible).
>


OK, so the build script needs to declare the repository in some way such
that your plugin can match it with the maven settings Id?

In that case, your best bet would be to force the user to declare the
repository "name" to match the value in settings.xml. Maybe something like:
1) in the build script:

publishing {
    repositories {
        maven {
            name "jboss-releases-repository"
        }
    }
}

2) In your plugin, you have would configure a repository with:

def configureRepository(MavenArtifactRepository rep) {
    def cred = lookupCredsForRepName(rep.name)
    rep.credentials {
        username = cred.username
        password = cred.password
    }
}

How to apply this code to each repository in your plugin? You have 2
options.
On the publishing extension:
publishing { // This will be lazily evaluated when the extension is
confiured
    repositories.withType(MavenArtifactRepository) { rep ->
        configureRepository(rep)
    }
}

OR on each PublishToMavenRepository task:

project.tasks.withType(PublishToMavenRepository) { publishTask ->
     configureRepository(publishTask.repository)
}

The downside to the second is that you'll be configuring the same
repository multiple times if it participates in multiple tasks.

(I haven't actually tested this code, but I believe that in principle these
approaches will work).

Hope that helps. Sorry I wasn't clearer with specific examples earlier.

cheers
Daz


>
>
> On Tue 16 Apr 2013 08:17:51 AM CDT, Steve Ebersole wrote:
>
>>
>> In rough that works:
>>
>>
>> // This is the kind of malarkey this plugin tries to address ~~~~~~
>> if ( ! hasProperty( "JBOSS_REPO_USER" ) ) {
>> JBOSS_REPO_USER = "";
>> }
>> if ( ! hasProperty( "JBOSS_REPO_PASS" ) ) {
>> JBOSS_REPO_PASS = "";
>> }
>> // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**~~~~~~~~~
>>
>> publishing {
>> repositories {
>> maven {
>> if ( project.version.endsWith( "SNAPSHOT" ) ) {
>> url snapshot-url
>> }
>> else {
>> url production-url
>> }
>>
>> credentials {
>> username = JBOSS_REPO_USER
>> password = JBOSS_REPO_PASS
>> }
>> }
>> }
>> }
>>
>> Now I just need to figure out:
>> 1) how to apply this programatically
>> 2) in such a way that does not trigger the lazy init of the publishing
>> block.
>>
>> As far as (2), the way I did this in the initial plugin code was to
>> use an Action that I applied as a doFirst to all
>> 'project.getTasks().withType( Upload.class )'. I think something
>> similar could be done against all 'project.getTasks().withType(
>> PublishToMavenRepository.class )'. Do you see a better option?
>>
>> Btw, the code is at
>> https://github.com/sebersole/**gradle-upload-auth-plugin<https://github.com/sebersole/gradle-upload-auth-plugin>.
>> The plugin
>> class which drives the processing is
>> org.hibernate.build.gradle.**upload.**UploadAuthenticationManager. The
>> Action class is org.hibernate.build.gradle.**upload.AuthenticationHandler
>>
>>
>>
>> On Tue 16 Apr 2013 07:44:20 AM CDT, Steve Ebersole wrote:
>>
>>>
>>>
>>> On Tue 16 Apr 2013 07:38:38 AM CDT, Luke Daley wrote:
>>>
>>>>
>>>>
>>>>
>>>>>
>>>>> Look, I just want to know what I need to do in order to apply a set
>>>>> of credentials to a maven repository to be used for upload. Is that
>>>>> possible? If so how?
>>>>>
>>>>
>>>>
>>>>
>>>> I'm having a lot of trouble understanding exactly what you are asking
>>>> for.
>>>>
>>>> What have you tried? What didn't work (in concrete terms)? What was
>>>> the stack trace?
>>>>
>>>> In what way does this not work for you:
>>>>
>>>> publishing {
>>>> publications {
>>>> mavenJava(MavenPublication) {
>>>> from components.java
>>>> }
>>>> }
>>>> repositories {
>>>> maven {
>>>> url …
>>>> credentials {
>>>> username = "foo"
>>>> password = "bar"
>>>> }
>>>> }
>>>> }
>>>> }
>>>>
>>>
>>>
>>>
>>> Finally! :)
>>>
>>> I have not tried anything, because I had no idea what to try. The
>>> documentation makes no (obvious) mention that I can apply credentials
>>> in this script block.
>>>
>>> I will try that now.
>>>
>>
> ------------------------------**------------------------------**---------
> To unsubscribe from this list, please visit:
>
>    
> http://xircles.codehaus.org/**manage_email<http://xircles.codehaus.org/manage_email>
>
>
>


-- 
Darrell (Daz) DeBoer
Principal Engineer, Gradleware
http://www.gradleware.com
Join us at the Gradle Summit 2013, June 13th and 14th in Santa Clara, CA:
http://www.gradlesummit.com

Reply via email to