Created
October 30, 2019 08:55
-
-
Save melix/574b32a710c5bf5063ee7a34c888697a to your computer and use it in GitHub Desktop.
Bridging with a Maven build
This file contains hidden or 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-library' | |
// Maven publish is just for tests, it would be replaced by the plugin plugin | |
id 'maven-publish' | |
} | |
group = "com.foo" | |
version = "1.0" | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
// declare a regular, GAV-based, dependency | |
implementation "com.byte-buddy:byte-buddy:${version}" | |
} | |
// ideally this should be defined in a separate file | |
project(":mavenBridge") { | |
// create an artifact, which will fail the build _only_ if explicitly requested and missing | |
def mavenArtifact = objects.fileProperty().fileProvider(providers.provider { | |
def file = file("../byte-buddy/target/byte-buddy-${version}.jar") | |
if (!file.exists()) { | |
throw new GradleException("Byte Buddy jar is missing at ${file}, please call the Maven build first") | |
} | |
file | |
}) | |
// declare an outgoing configuration which will "carry" the artifact generated by the Maven build | |
configurations { | |
mavenBridge { | |
canBeResolved = false | |
canBeConsumed = true | |
attributes { | |
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, 'java-api')) | |
} | |
outgoing.artifact(mavenArtifact) | |
} | |
} | |
} | |
configurations.all { | |
resolutionStrategy.dependencySubstitution { | |
substitute module("com.byte-buddy:byte-buddy:${version}") with project(":mavenBridge") | |
} | |
} | |
// The latter is for testing publications | |
publishing { | |
repositories { | |
maven { url "${buildDir}/repo" } | |
} | |
publications { | |
maven(MavenPublication) { | |
from components.java | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment