0

我编写了一个 gradle 脚本,在其中创建 zip 和 war 文件,然后我需要将其上传/发布到工件,但问题是我在工件任务中指定了 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
}
4

1 回答 1

0

根据gradle 分发插件文档

“src/$distribution.name/dist”目录中的所有文件将自动包含在分发中。

并且,

分发插件将分发档案添加为默认发布工件的候选者。

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

为了解决此问题,您可能可以做的是通过明确排除不需要的文件来更准确地定义contents copySpec,即:

distributions {
  main { 
    contents { 
      exclude('**/.zip')
      exclude('**/.tar')
      from {
        war.outputs
      }
    }
  }
}

请注意,我并没有自己尝试上述方法,因此可能需要进行一些微调。不过我相信你可以在CopySpec Interface文档中找到你需要的数据

于 2015-04-17T07:31:12.253 回答