4

I hope this is not a duplicate because I definitely had searched around including a similar question. I believe it's probably same symptom, but a very different error.

I'm trying to build an Android library project, but release it as a .jar. And version the Jar filed, publish it to our internal Artifactory repositories.

I followed this official guide, but still hit a weird "Context URL cannot be empty" error: Gradle+Artifactory+Plugin

My build.gradle:

buildscript {
    /*
     * For adding Gradle Artifactory Plugin
     */
    repositories {
        maven {
            url 'https://artifactory.mydomain.net/artifactory/libs-release'
        }
    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.2.+'
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}

version = "1.0.0"
group = 'com.myorg.network'

apply plugin: 'maven'
apply plugin: 'artifactory'
apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName project.version
    }
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
}

// https://stackoverflow.com/questions/19307341/android-library-gradle-release-jar
android.libraryVariants.all { variant ->
    def name = variant.buildType.name
    if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
        return; // Skip debug builds.
    }
    def task = project.tasks.create "jar${name.capitalize()}", Jar
    task.dependsOn variant.javaCompile
    task.from variant.javaCompile.destinationDir
    artifacts.add('archives', task);
}

repositories {
    maven {
        url 'https://artifactory.mydomain.net/artifactory/libs-release'
    }
}

dependencies {
    compile files('libs/volley.jar')

    compile 'commons-lang:commons-lang:2.5'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.squareup:otto:1.3.4'
    compile 'com.squareup:tape:1.2.0'
    compile 'org.apache.commons:commons-compress:1.3'
    compile 'org.slf4j:slf4j-api:1.7.5'

    instrumentTestCompile 'org.mockito:mockito-all:1.9.5'
    instrumentTestCompile 'com.google.dexmaker:dexmaker:1.0'
    instrumentTestCompile('com.google.dexmaker:dexmaker-mockito:1.0') {
        // Stuff breaks without this.
        // See http://forums.gradle.org/gradle/topics/how_to_exclude_transitive_dependency
        exclude group: 'org.hamcrest', module: 'hamcrest-core'
        exclude group: 'org.objenesis', module: 'objenesis'
        exclude group: 'org.mockito', module: 'mockito-core'
    }
}


artifactory {
  contextUrl = 'https://artifactory.mydomain.net/artifactory'
  publish {
    contextUrl = 'https://artifactory.mydomain.net/artifactory'
    repository {
      repoKey = 'libs-release-local'
      username = 'xbeta'
      password = 'password'
      maven = true
    }
  }
  resolve {
    repository {
      repoKey = 'libs-release'
    }
  }
}

Build failure:

$ ./gradlew --info clean artifactoryPublish
Starting Build
Settings evaluated using settings file '/Users/xbeta/workspace/rest-client/settings.gradle'.
Projects loaded. Root project using build file '/Users/xbeta/workspace/rest-client/build.gradle'.
Included projects: [root project 'rest-client', project ':rest-client']
Evaluating root project 'rest-client' using build file '/Users/xbeta/workspace/rest-client/build.gradle'.
Evaluating project ':rest-client' using build file '/Users/xbeta/workspace/rest-client/rest-client/build.gradle'.
Compiling build file '/Users/xbeta/workspace/rest-client/rest-client/build.gradle' using BuildScriptClasspathScriptTransformer.
Compiling build file '/Users/xbeta/workspace/rest-client/rest-client/build.gradle' using BuildScriptTransformer.
All projects evaluated.

FAILURE: Build failed with an exception.

* What went wrong:
Context URL cannot be empty

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 13.165 secs
Stopped 0 Gradle compiler daemon(s).

Edited run with --stacktrace :

* Exception is:
java.lang.IllegalStateException: Context URL cannot be empty
    at org.jfrog.build.client.ArtifactoryClientConfiguration.getContextUrl(ArtifactoryClientConfiguration.java:130)
    at org.jfrog.build.client.ArtifactoryClientConfiguration$ResolverHandler.getContextUrl(ArtifactoryClientConfiguration.java:223)
    at org.jfrog.build.client.ArtifactoryClientConfiguration$RepositoryConfiguration.getUrl(ArtifactoryClientConfiguration.java:467)
    at org.jfrog.build.client.ArtifactoryClientConfiguration$RepositoryConfiguration$getUrl.call(Unknown Source)
    at org.jfrog.gradle.plugin.artifactory.ArtifactoryPluginBase$ProjectsEvaluatedBuildListener.defineResolvers(ArtifactoryPluginBase.groovy:77)
    at org.jfrog.gradle.plugin.artifactory.ArtifactoryPluginBase$ProjectsEvaluatedBuildListener.this$3$defineResolvers(ArtifactoryPluginBase.groovy)
    at org.jfrog.gradle.plugin.artifactory.ArtifactoryPluginBase$_ProjectsEvaluatedBuildListener_projectsEvaluated_closure1.doCall(ArtifactoryPluginBase.groovy:68)
    at org.jfrog.gradle.plugin.artifactory.ArtifactoryPluginBase$ProjectsEvaluatedBuildListener.projectsEvaluated(ArtifactoryPluginBase.groovy:66)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy14.projectsEvaluated(Unknown Source)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy14.projectsEvaluated(Unknown Source)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:145)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
    at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:46)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.Main.main(Main.java:37)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)

Edited I found this works, but not sure why this would work, is it a bug? Why do I need contextUrl in 3 places to get this working where it's pointing to the same url? The contextUrl set on artifactory block should be apply to both publish and resolve blocks?:

artifactory {
  contextUrl = 'https://artifactory.mydomain.net/artifactory'
  publish {
    contextUrl = 'https://artifactory.mydomain.net/artifactory'
    repository {
      repoKey = 'libs-release-local'
      username = 'xbeta'
      password = 'password'
      maven = true
    }
  }
  resolve {
    contextUrl = 'https://artifactory.mydomain.net/artifactory'
    repository {
      repoKey = 'libs-release'
    }
  }
} 
Community
  • 1
  • 1
samxiao
  • 2,587
  • 5
  • 38
  • 59
  • can you please run with --stacktrace flag? – JBaruch Feb 08 '14 at 21:21
  • It looks like a bug indeed. We'll look into it. – JBaruch Feb 09 '14 at 09:59
  • @JBaruch I also find another bug, you want me to post it here too? In this very same code snippet. Looks like the Artifactory Gradle Plugin is full of these types of bugs – samxiao Feb 09 '14 at 17:18
  • It's pretty much bug-free when used with java plugin. Not very compatible with android plugin, though. Feel free to report in [our Jira](https://www.jfrog.com/jira/browse/GAP). Thanks! – JBaruch Feb 10 '14 at 13:51

0 Answers0