Copy dependencies with type


#1

I’ve integrated a library through ivy. It provides other artifacts with a special type. When copying I would like to have only a type sql.

ivy.xml

<configurations>
<conf name="default" visibility="public"/>
<conf name="runtime" visibility="public"/>
<conf name="provided" visibility="public"/>
</configurations>
<publications>
<artifact name="libary1" type="jar" ext="jar" conf="default"/>
<artifact name="libary2" type="jar" ext="jar" conf="default"/>
<artifact name="sql" type="sql" ext="zip" conf="provided"/>
<artifact name="module" type="module" ext="zip" conf="provided"/>
<artifact name="reports" type="report" ext="zip" conf="provided"/>
<artifact name="definition1" type="standard" ext="zip" conf="provided"/>
<artifact name="definition2" type="standard" ext="zip" conf="provided"/>
<artifact name="definition3" type="standard" ext="zip" conf="provided"/>
<artifact name="definition4" type="standard" ext="zip" conf="provided"/>
<artifact name="definition5" type="standard" ext="zip" conf="provided"/>
<artifact name="definition6" type="standard" ext="zip" conf="provided"/>
<artifact name="libweb" type="web" ext="war" conf="provided"/>
</publications>

build.gradle

configurations {
	provided{}
}

dependencies {
    provided  group: 'com.group', name: 'libname', version: '1.0', configuration: 'provided'
}


task distribute () << 
	copy	{
		from 	{
			configurations.provided
                    inclcude  ....
		}
		into dest
		rename { name ->
			def artifacts = configurations.provided.resolvedConfiguration.resolvedArtifacts
			def artifact = artifacts.find { it.file.name == name }
			"${artifact.name}.${artifact.extension}"
		}
	}
}

#2

I could solve the problem now

task createDistribution()	{
	File output = file ("$buildDir/distribution")
	outputs.dir(output)
	inputs.files(configurations.libprovided.resolvedConfiguration.files)

	doLast	{
		configurations.ikitprovided.resolvedConfiguration.resolvedArtifacts.each { artifact ->
			def result
			switch(artifact.type)	{
				case  "jar":
					result = 'lib/java'
					break
				case  "web":
					result = 'lib/java'
					break
				case "sql":
					result = 'update/sql'
					break
				default:
					result = 'unbekannt'
					break
			}
			logger.info "Copy ${artifact.name}"
			copy {
				from artifact.file
		   		into new File(output, result)
		    	rename { name ->"${artifact.name}.${artifact.extension}"}
			}
		}
	}
}