-
-
Save lukebemish/5b79f393c6a44e31311a8b8f18844c9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'java' | |
id 'maven-publish' | |
} | |
group = 'org.example' | |
version = '1.0.0' | |
configurations { | |
hasSecondaryVariants { | |
attributes.attribute Usage.USAGE_ATTRIBUTE, objects.named(Usage, 'something-unique') | |
} | |
} | |
abstract class WriteTask extends DefaultTask { | |
@OutputFile | |
abstract RegularFileProperty getOutputFile() | |
@Input | |
abstract Property<String> getText() | |
@TaskAction | |
void write() { | |
def file = outputFile.get().asFile | |
file.text = getText().get() | |
} | |
} | |
tasks.register('write', WriteTask) { | |
outputFile = file('write.txt') | |
text = 'Hello, world!' | |
} | |
tasks.register('writeSecondary', WriteTask) { | |
outputFile = file('writeSecondary.txt') | |
text = 'Hello, world! But different' | |
} | |
artifacts { | |
hasSecondaryVariants(tasks.write.outputFile) { | |
builtBy tasks.write | |
type = 'text' | |
classifier = 'primary' | |
} | |
} | |
configurations.hasSecondaryVariants.outgoing.variants { | |
secondary { | |
attributes { | |
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, 'something-else-unique')) | |
} | |
artifact(tasks.writeSecondary.outputFile) { | |
builtBy tasks.writeSecondary | |
type = 'text' | |
classifier = 'secondary' | |
} | |
} | |
} | |
def component = (AdhocComponentWithVariants) components.java | |
component.addVariantsFromConfiguration(configurations.hasSecondaryVariants) {} | |
publishing { | |
publications { | |
mavenJava(MavenPublication) { | |
from components.java | |
} | |
} | |
repositories { | |
maven { | |
url = "$projectDir/repo" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment