Search code examples
javagradlelibgdxartifactory

Publishing libgdx core to artifactory


I'm am trying to publish an in-house libGDX framework to use for all the games I work on using artifactory. I have been following this guide, however, I am stuck at the point in which the project itself is actually published. My libGDX project only has a core module, as it is not a game in itself, so I did not make a desktop or android module. This is my buildscript for the whole project

buildscript {


    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"

    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "lichengine"
        gdxVersion = '1.9.8'
        roboVMVersion = '2.3.3'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile group: 'org.json', name: 'json', version: '20160810'
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"

    }
}

tasks.eclipse.doLast {
    delete ".project"
}

And here is the buildscript for the core module

apply plugin: "java"
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
    name = appName + "-core"
}
def libraryGroupId = 'my.com.lichengine'
def libraryArtifactId = 'lichengine'
def libraryVersion = '1.0'
publishing {
    publications {
        aar(MavenPublication) {
            groupId libraryGroupId
            version libraryVersion
            artifactId libraryArtifactId

            artifact("$buildDir/publications/aar/${artifactId}-release.aar")
        }
    }
}

artifactory {
    contextUrl = 'http://mywebsite.com:8081/artifactory'
    publish {
        repository {
            repoKey = 'libs-release-local'

            username = artifactory_username
            password = artifactory_password
        }
        defaults {
            publications('aar')
            publishArtifacts = true

            properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
            publishPom = true
        }
    }
}

When I try to run the artifactoryPublish task on the root project or the core project I get the following error:

lichengine\core\build\publications\aar\lichengine-release.aar' does not exist, and need to be published from publication aar

Am I missing something? Everything I search for online is specifically for android libraries so nothing really helps.It seems like an aar file that is supposed to be generated is not.


Solution

  • After a lot of pain, I figured it out. Instead of using an aar publication I am using mavenJava. Here is my updated publications block:

    publications {
            mavenJava(MavenPublication) {
                groupId libraryGroupId
                version libraryVersion
                artifactId libraryArtifactId
                from components.java
            }
        }
    

    I also had to update the defaults block

    defaults {
                publications ('mavenJava')
                publishArtifacts = true
    
                properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
                publishPom = false
            }
    

    Hopefully, anyone who sees this can use this to help them make libGDX libraries with artifactory!