🚧 Gradle 6 - Dependency constraints

This commit is contained in:
Johnathan Gilday 2019-12-17 20:46:47 -05:00
parent 36be6908fe
commit f95a1a2011
4 changed files with 60 additions and 9 deletions

View File

@ -6,9 +6,36 @@ plugins {
group = "com.baeldung"
version = "1.0.0"
repositories {
mavenCentral()
}
dependencies {
api("io.reactivex.rxjava2:rxjava:2.2.16")
implementation("com.google.guava:guava") {
version {
require("2.0")
prefer("28.1-jre")
because("Only uses ImmutableList type, so any version since 2.0 will do, but tested with 28.1-jre")
}
}
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
}
tasks.compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.test {
useJUnitPlatform()
}
publishing {
publications {
register("mavenJava", MavenPublication::class) {
register<MavenPublication>("mavenJava") {
from(components["java"])
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.gradle;
public class HelloWorld {
public String sayHello() {
return "Hello, world!";
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.gradle;
import com.google.common.collect.ImmutableList;
import io.reactivex.Observable;
import java.util.List;
/** Demonstrates a library type that returns an RxJava type. */
public class RxHelloWorld {
/** @return an {@link Observable} that emits events "hello" and "world" before completing. */
public static Observable<String> hello() {
// Guava ImmutableList class is an implementation detail.
List<String> values = ImmutableList.of("hello", "world");
return Observable.fromIterable(values);
}
private RxHelloWorld() {}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.gradle;
import static com.baeldung.gradle.RxHelloWorld.hello;
import org.junit.jupiter.api.Test;
/** Unit test for {@link RxHelloWorld}. */
final class RxHelloWorldUnitTest {
@Test
void it_emits_hello_world_values() {
hello().test().assertValues("hello", "world").assertComplete();
}
}