18

I'm new working with Gradle and Artifactory and I used an example that is not working correctly from this example site I have this error message:

Extension of type 'PublishingExtension' does not exist. Currently registered extension types: [DefaultExtraPropert iesExtension, DefaultArtifactPublicationSet_Decorated, ReportingExtension_Decorated, DefaultProjectComponentContai ner_Decorated, DefaultProjectSourceSet_Decorated, DefaultBinaryContainer_Decorated]

I have an error in this line:

defaults{
    publications ('mavenJava')
}

Some one could help me with this I have been stuck in this issue for so long.

After reviewing the links as JBaruch recommended and compare with the code I changed the plugin but still the same problem. Maybe I'm confusing something? (That is why I will post the whole source code)

buildscript {
    repositories {
        maven {
            url 'http://.../artifactory/libs-release'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
            name = "maven-main-cache"
        }
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
    }
}

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

version = '1.0.0-SNAPSHOT'
group = 'com.buransky'

repositories {
    add buildscript.repositories.getByName("maven-main-cache")
}

dependencies {
    compile 'org.scala-lang:scala-library:2.11.2'
}

tasks.withType(ScalaCompile) {
    scalaCompileOptions.useAnt = false
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'libs-snapshot-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
        defaults{
            publications ('mavenJava')
        }
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

Thank you very much

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Mäū Cárdenas
  • 251
  • 1
  • 4
  • 7

2 Answers2

20

You didn't apply the maven-publish plugin that is expected to be present with artifactory plugin.

Please take a look at the documentation, also this answer might help (note the plugins names change).

Community
  • 1
  • 1
JBaruch
  • 22,610
  • 5
  • 62
  • 90
  • 1
    I applied the plugin: 'maven-publish' as the example and I checked if the version of the plugin is correct because as you said the names changes (in this case com.jfrog.artifactory), but still no result at all. I posted my source code FYI thank you. – Mäū Cárdenas Feb 18 '15 at 15:06
  • I tried all kind of plugins but still I don't have any sucess and it keeps having same problems on publications(mavenJava) reference. Might be related to a maven repository? – Mäū Cárdenas Feb 18 '15 at 20:58
  • I was trying to use the artifactory plugin for gradle & android today as well, same error as yourself. The artifactory example at https://github.com/JFrogDev/project-examples/tree/master/gradle-android-aar is a few versions behind the most recent android gradle plugin...and also doesn't have the "maven-publish" plugin. – McNinja Feb 19 '15 at 02:25
  • Which Gradle version are you on, guys? – JBaruch Feb 19 '15 at 10:45
  • 1
    Problem solved my mistake was I wasn't using the main build.gradle on the root because I had different moduls and I was running the publication from one of those. The code is perfect thank you so much JBaruch. My gradle version is 2.1 – Mäū Cárdenas Feb 19 '15 at 13:46
  • Great, cause I was quite puzzled. Your code looks good, should work. Answer acceptance appreciated. – JBaruch Feb 19 '15 at 14:42
  • Another thing to note: I recently had conflict because I called the plugin (com.jfrog.artifactory) twice in different modules (parent and child build.gradle) that wouldn't allow publish. Thanks again! – Mäū Cárdenas Feb 19 '15 at 20:08
  • That's can't happen. Gradle allows multiple plugin application without any side effects. – JBaruch Feb 19 '15 at 20:23
4

I lost a lot of time on this since Artifactory docs use outdated Android Studio & gradle plugins versions, so here is my working conf with AS 1.5.1 and gradle 1.5.0 :

global build.gradle

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
  }
}

module build.gradle

apply plugin: 'com.jfrog.artifactory'
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

publishing{
  publications {
    maven(MavenPublication)  {
        groupId packageName
        version = libraryVersion
        artifactId project.getName()
        artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
    }
  }
}

artifactory {
  contextUrl = // yours
  publish {
    repository {
        // The Artifactory repository key to publish to
        repoKey = 'libs-release-local'
        username = // yours
        password = // yours
    }
    defaults {
        publishArtifacts = true
        publications ('maven')

        // Properties to be attached to the published artifacts.
        properties = ['qa.level': 'basic', 'dev.team': 'core']
        // Publish generated POM files to Artifactory (true by default)
        publishPom = true
    }
  }
}
Rémy DAVID
  • 4,343
  • 6
  • 25
  • 27