vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.74k stars 637 forks source link

Explain Gradle + Vavr custom pattern ($Patterns/$Unapply) #2339

Open sir4ur0n opened 5 years ago

sir4ur0n commented 5 years ago

When using Vavr with $Patterns / $Unapply, one must add additional configuration to its dependencies, otherwise Gradle does not process annotations by default.

This would be nice to mention this in the documentation.

It seems that annotationProcessor("io.vavr", "vavr-match-processor", vavrVersion) does the trick.

danieldietrich commented 5 years ago

Thanks for the hint, will do!

Do you have (a minimal) Gradle config that I can take as example?

sir4ur0n commented 5 years ago
plugins {
    java
}

group = "com.sir4ur0n.github"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    val vavrVersion = "0.10.0"
    // Provides @Patterns, @Unapply, Tuple0..8
    implementation("io.vavr", "vavr", vavrVersion)
    // Processes patterns during compilation, outputs them in build/classes by default
    annotationProcessor("io.vavr", "vavr-match-processor", vavrVersion)
}

configure<JavaPluginConvention> {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}
danieldietrich commented 5 years ago

@Sir4ur0n thank you, that helps! I think there also needs to be the additional dependency

compileOnly("io.vavr", "vavr-match", vavrVersion)
sir4ur0n commented 5 years ago

Not needed explicitly, it's a transitive dependency of io.vavr:vavr. Anyway you also need io.vavr:vavr tu build patterns using Tuple0..8.

danieldietrich commented 5 years ago

I see. That is interesting because vavr-match should only be a compile time dependency of Vavr. I think the dependency 'leaked' into the library with the PR #2294.

I need to fix that in the next version.

screenshot 2019-01-26 at 17 04 13

nfekete commented 5 years ago

compile is the default scope in maven if no scope is specified. <scope>compile</scope> thus should be redundant. See maven docs.

danieldietrich commented 5 years ago

Sorry, I confused Maven’s compile with Gradle’s compileOnly. What I meant was that we might need s.th. like Maven’s provided in order not to leak vavr-match as transitive dependency.

See https://blog.gradle.org/introducing-compile-only-dependencies

The important parts:

29287701-7613-4890-9725-826157b07cd4 75f8f935-defb-41cc-a0e3-c7458d29999a

Opalo commented 3 years ago

@Sir4ur0n do you have a working example of using pattern matching with annotation processor with gradle? I've added a dependency but still cannot compile it.

sir4ur0n commented 3 years ago

I haven't developed in Java in many years, I won't be able to help you :sweat_smile:

Opalo commented 3 years ago

Ok, thanks. Managed to do that on my own ;)

Opalo commented 3 years ago

Here is my answer to the question that I was working on.