在gradle中发布具有依赖项的测试jar

在gradle中发布具有依赖项的测试jar,gradle,build.gradle,Gradle,Build.gradle,我在src/integTests目录下为我的项目编写了测试,现在我必须只构建和发布由integ测试生成的jar。这是我的密码: apply plugin: 'java' apply plugin: 'maven-publish' sourceSets { integTest { java.srcDir file('src/integTest/java') resources.srcDir file('src/integTest/resources')

我在src/integTests目录下为我的项目编写了测试,现在我必须只构建和发布由integ测试生成的jar。这是我的密码:

apply plugin: 'java'
apply plugin: 'maven-publish'

sourceSets {
    integTest {
        java.srcDir file('src/integTest/java')
        resources.srcDir file('src/integTest/resources')
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
    }
}

configurations {
    integTestCompile.extendsFrom testCompile
    integTestRuntime.extendsFrom testRuntime
}

task integTestJar (type:Jar) {
    from sourceSets.integTest.output
        appendix = 'integ-tests'
}

publishing {
      publications {
          myPublicationName(MavenPublication) {
              artifactId "client-security-internal-integ-tests"
              from components.java            
          }
      }
      repositories {
          maven {
              url ="${artifactory_contextUrl}"
              credentials {
                  username = "${artifactory_user}"
                  password = "${artifactory_password}"
              }
          }
      }
}
在上面,当我使用components.java中的
时,它会以artifact-id中指定的名称发布产品的jar。相反,当我使用
artifact integetstjar.archivePath
时,它会发布正确的jar,但不会在pom文件中包含依赖项信息

我尝试从components.integTest
中执行
,但失败,出现错误
在SoftwareComponentInternal集合上找不到属性“integTest”


如何发布包含在pom文件中的所有依赖项的integ测试jar?

以下是有效的解决方案

        pom.withXml {
            def dependencies = asNode().appendNode('dependencies')
            configurations.integTestRuntime.getResolvedConfiguration().getFirstLevelModuleDependencies().each {
                def dependency = dependencies.appendNode('dependency')
                dependency.appendNode('groupId', it.moduleGroup)
                dependency.appendNode('artifactId', it.moduleName)
                dependency.appendNode('version', it.moduleVersion)
            }
        }