Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install all modules artifacts to custom maven repository using Gradle and Android Studio

I have a pure Java lib that I use in my Android project, I'm trying to configure it so when I run 'gradle install' it will build the entire project and install all the artifacts to a custom local repository which is evidently a git repository.

This is the module gradle file, the project builds fine:

group 'com.packagenaem'
def artifact = 'artifactname'
version '1.0.0'
apply plugin: 'java'

def MAVEN_LOCAL_PATH = 'file:///some/path/to/my/repo'

uploadArchives {
    repositories {
        apply plugin: 'maven'
        mavenInstaller {
            repository(url: MAVEN_LOCAL_PATH)
            pom.groupId = group
            pom.artifactId = artifact
            pom.version = version
            pom.packaging = 'jar'
        }
    }
}

task sourcesJar(type: Jar, dependsOn:classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn:javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

The error I get when running from command line is:

Could not find method repository() for arguments [{url=file:///some/path/to/my/repo}] on repository container

If I omit this line repository(url: MAVEN_LOCAL_PATH) then it installs all the artifacts very nicely to the /users/$USER/.m2/repository

=== UPDATE ===

After playing with it a bit when executing the following gradle uploadArchive, I got to a point where I get the following error:

Failed to deploy artifacts/metadata: No connector available to access repository remote (/some/path/to/my/custom/repo) of type default using the available factories WagonRepositoryConnectorFactory

==== EXTENDING THIS QUESTION A BIT ====

So since I've already set a bounty for this question, lets extend it and ask how can I make it so that I'll write the above code once in my project gradle file and upon "gradle uploadArchives" it will deploy the artifacts of all projects? currently I've duplicated all the code cross all the build gradle files I have and I hate this sort of solution...

like image 635
TacB0sS Avatar asked Jul 31 '15 00:07

TacB0sS


1 Answers

OK, so I've wasted a lot of time and brain cells on this one...

Instead of declaring:

repository(url: file("/some/path/to/my/custom/repo"))

Change it to:

repository url: 'file://' + new File("/some/path/to/my/custom/repo").absolutePath

I have no idea why but now every configuration I try works...

like image 93
TacB0sS Avatar answered Nov 01 '22 19:11

TacB0sS