Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39758

Artifactory plugin does not publish simple gradle project

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • artifactory-plugin
    • None
    • Jenkins: 2.30
      Artifactory plugin: 2.8.1

      I started with the sample multi-project gradle build provided here:

      https://github.com/JFrogDev/project-examples/tree/master/gradle-examples/4/gradle-example-ci-server

      The publish to Artifactory via the Jenkins plugin worked just fine. I then started stripping out the multiple modules and brought it down to just one module (the 'shared') module and then moved the source of the shared module to the top level, effectively making it a simple gradle project.

      The Jenkins Artifactory plugin no now longer publishes the artifact to Artifactory. I dug into the temporary file that is generated by this plugin and found the below:

      // Set the "archives" configuration to all Artifactory tasks.
      for (Project p : root.getAllprojects()) {
      Task t = p.getTasks().findByName(ArtifactoryTask.BUILD_INFO_TASK_NAME)
      if (t != null)

      { ArtifactoryTask task = (ArtifactoryTask)t task.setAddArchivesConfigToTask(true) }

      }

      Does this mean that the root project can not be published to artifactory via this mechanism and that all gradle projects have to have a sub-project that produces the artifact in order for this plugin to publish it to Artifactory. That would seem like an unreasonable restriction and would like to confirm.

          [JENKINS-39758] Artifactory plugin does not publish simple gradle project

          Sud Ramasamy added a comment -

          I found JENKINS-39755 and as per that issue, when I downgraded to 2.7.2 the publish from the root project worked. The generated gradle artifactory plugin file does look the same though. So I don't think my original analysis of this issue is valid.

          Sud Ramasamy added a comment - I found JENKINS-39755 and as per that issue, when I downgraded to 2.7.2 the publish from the root project worked. The generated gradle artifactory plugin file does look the same though. So I don't think my original analysis of this issue is valid.

          I think I figured this one out. I did it using the sample project RX14 provided in this jira issue:
          https://issues.jenkins-ci.org/browse/JENKINS-39755

          The issue is not with the "root.getAllprojects()" API. This API actually returns all projects, including the root. The issue is in the ProjectsEvaluatedBuildListener class. It looks like the afterEvaluate method is not invoked when the project has no modules, and therefore, the root project task is not added to the artifactoryTasks set. To fix the issue, I modified the projectsEvaluated method in this class, by adding the following 2 lines to it:

          Set<Task> tasks = gradle.rootProject.getTasksByName(BUILD_INFO_TASK_NAME, false)
          artifactoryTasks.addAll(tasks)

          Here's the method after the change:

          def void projectsEvaluated(Gradle gradle) {
          // Make sure the plugin is applied to the root project.
          gradle.rootProject.getPluginManager().apply(ArtifactoryPlugin.class)
          // Configure the artifactoryPublish tasks. Deployment happens on task execution.
          Set<Task> tasks = gradle.rootProject.getTasksByName(BUILD_INFO_TASK_NAME, false)
          artifactoryTasks.addAll(tasks)
          artifactoryTasks.each

          { BuildInfoBaseTask bit -> evaluate(bit) }

          }

          That fixed the issue for me. I'd like to test this a bit, and then publish a snapshot version of the plugin, so that you guys can try it out also.

          Eyal Ben Moshe added a comment - I think I figured this one out. I did it using the sample project RX14 provided in this jira issue: https://issues.jenkins-ci.org/browse/JENKINS-39755 The issue is not with the "root.getAllprojects()" API. This API actually returns all projects, including the root. The issue is in the ProjectsEvaluatedBuildListener class. It looks like the afterEvaluate method is not invoked when the project has no modules, and therefore, the root project task is not added to the artifactoryTasks set. To fix the issue, I modified the projectsEvaluated method in this class, by adding the following 2 lines to it: Set<Task> tasks = gradle.rootProject.getTasksByName(BUILD_INFO_TASK_NAME, false) artifactoryTasks.addAll(tasks) Here's the method after the change: def void projectsEvaluated(Gradle gradle) { // Make sure the plugin is applied to the root project. gradle.rootProject.getPluginManager().apply(ArtifactoryPlugin.class) // Configure the artifactoryPublish tasks. Deployment happens on task execution. Set<Task> tasks = gradle.rootProject.getTasksByName(BUILD_INFO_TASK_NAME, false) artifactoryTasks.addAll(tasks) artifactoryTasks.each { BuildInfoBaseTask bit -> evaluate(bit) } } That fixed the issue for me. I'd like to test this a bit, and then publish a snapshot version of the plugin, so that you guys can try it out also.

          We opened the following issue to track this fix:
          https://www.jfrog.com/jira/browse/HAP-843
          HAP-843 includes a download link for a snapshot version with a fix. We'd appreciate your feedback for it.

          Eyal Ben Moshe added a comment - We opened the following issue to track this fix: https://www.jfrog.com/jira/browse/HAP-843 HAP-843 includes a download link for a snapshot version with a fix. We'd appreciate your feedback for it.

            eyalbe Eyal Ben Moshe
            sudr Sud Ramasamy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: