How to get the latest.integration version number


(Stephane Galles) #1

I’m trying create a plugin that is able to increment the version number of the projet for each uploadArchives, but I’m not able to fetch le the real latest.integration version number in the repos.

Basically, in the plugin, I create a configuration for the project itself :

configurations {
   selfConf {
    visible = true
    transitive = false
   }
  }
      dependencies {
   selfConf group:project.group, name:project.name, version:'latest.integration'
       }
      task doesNotWork << {
   project.configurations.selfConf.resolvedConfiguration.resolvedArtifacts.each { t ->
    println t
   }
       }

The ‘doesNotWork’ task throws a NPE in the gradle code. Is my approach too naive ?

Thank you


(René Groeschke) #2

Hello, did you declare the repository, where your archives are uploaded to? Can you provide the stack trace of the NPE using the “-S” option when running your build.

regards, René


(Stephane Galles) #3

Yes, the repository is declared. Actually, I’ve done more tests and I’ve found out that the NPE is clearly related to the configuration targeting the group/name of the enclosing project itself. ie : - On projet A the ‘doesNotWork’ task works when I target module B on the repos, but does not work for when I target A - On projet B the ‘doesNotWork’ task works when I target module A on the repos, but does not work for when I target B

This is with Gradle m8a, with an Ivy http resolver.

The end of the stacktrace
:
by: java.lang.NullPointerException
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.getArtifacts(DependencyGraphBuilder.java:651)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.attachToParents(DependencyGraphBuilder.java:356)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ConfigurationNode.attachToParents(DependencyGraphBuilder.java:764)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.assembleResult(DependencyGraphBuilder.java:140)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:56)
        at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:67)
        at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:36)
        at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:34)
        at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:99)
        at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:49)
        at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:34)
        at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:42)
        at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:78)
        at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:36)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getResolvedConfiguration(DefaultConfiguration.java:237)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getResolvedConfiguration(Unknown Source)

(Stephane Galles) #4

Should I create a bug for this NPE ?

Regards


(Stephane Galles) #5

I don’t know if something was wrong with my first code, but I’ve found a hack to make it work. It seems that somehow I’m not supposed to create a configuration with the artifact of the project itself, never mind, let’s create an other project to hide this new conf.

Fasten your seatbelt, this is not pretty :

task displayLatestPublication << {
    Project sandBox = org.gradle.testfixtures.ProjectBuilder.builder().withName('dummyName').build()
    sandBox.repositories.addAll(project.repositories)
    sandBox.configurations {
        selfConf {
            transitive = false
        }
    }
    sandBox.dependencies {
        selfConf group:project.group, name:project.name, version:'latest.integration'
    }
    sandBox.configurations.selfConf.resolvedConfiguration.resolvedArtifacts.each { t ->
        println t
    }
}

Well, at least I think that I can create my plugin now…that will break as soon as ProjectBuilder is removed from the runtime classpath of Gradle, to prevent this type of hack !