gradle - 没有在gradle脚本中将提到的文件(war/tar/zip)发布到 Artifactory

标签 gradle build.gradle artifactory gradle-plugin

我写了一个gradle脚本,在其中创建zip和war文件,然后需要将其上传/发布到 Artifact ,但是问题是我在 Artifact 任务中指定了war文件,即使该文件将所有内容都发布到了zip文件中,tar和war,而不仅仅是war文件。

apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'distribution'

//-- set the group for publishing
group = 'com.xxx.discovery'

/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream { 
    stream -> buildProperties.load(stream) 
} 
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.coveryadBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.coveryadBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.aaa.covery"
version = buildProperties.discoveryadBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

  repositories {
    maven {
      url "http://cxxxxt.tshaaaaa.tho.com:9000/artifactory/libselease"
    }
    maven {
      url "http://cxxxxt.tshaaa.tho.com:9000/artifactory/cache"
    }
  }

dependencies {
    compile ([
    "com.uters.omni:HermesSessionAPI:1.2",
    "com.uters.proxy:ProxyResources:1.1",
    "com.uters.omni:SeshataDirectory:1.0.1" ,
    "com.euters.omni:CybeleInfrastructure:1.1.2",
    "com.euters:JSONBus:1.4.1",
    "javaee:javaee-api:5"
    ])
}

distributions {
  main { 
    contents { 
      from {
        war.outputs
        }
      }
  }
}

// for publishing to artifactory
artifacts {
  archives war
}

最佳答案

根据gradle distribution plugin documentation:

All of the files in the “src/$distribution.name/dist” directory will automatically be included in the distribution.



并且,

The distribution plugin adds the distribution archives as candidate for default publishing artifacts.



换句话说,默认情况下,所有文件都会被发布,因此这可以解释您遇到的行为。

为了解决此问题,您可能可以做的是通过显式排除不需要的文件来更准确地定义contents copySpec,即:
distributions {
  main { 
    contents { 
      exclude('**/.zip')
      exclude('**/.tar')
      from {
        war.outputs
      }
    }
  }
}

请注意,尽管我自己没有尝试过上述操作,所以可能需要进行一些微调。但是我相信您可以在 CopySpec Interface documentation中找到所需的数据

关于gradle - 没有在gradle脚本中将提到的文件(war/tar/zip)发布到 Artifactory ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29687270/

相关文章:

java - 使用 Gradle 的 JAR 中的 META-INF/服务

docker - 没有 list 的 Artifactory docker 镜像

plugins - 使用Jenkins Artifactory插件发布构建信息但不部署 Artifactory

intellij-idea - 在IDEA中似乎没有gradle导入支持

gradle - 使用gradle时如何将jar/war依赖项添加到ant文件集?

android - Unity GoogleMobileAdsMediationTestSuite 抛出异常 setAdListener 必须在主 UI 线程上调用

android - 如何为gradle设置代理服务器?

gradle - 引用静态库目录 gradle 时构建期间的问题

java.net.SocketException : Permission denied: listen failed with Gradle

repository - 神器中的 Gradle 发行版存储库已过时?