Search code examples
javagradlemanifold

Can't use Manifold in gradle java project


I have a project based on JDK 11, and I want to use Manifold (http://manifold.systems/) in my java project.

My build.gradle:

 plugins {
    id 'java'
}
//

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

dependencies {
    implementation 'org.projectlombok:lombok:1.18.18'
    implementation "io.vavr:vavr:0.10.3"
    implementation 'systems.manifold:manifold-science:2021.1.25'
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
    annotationProcessor group: 'systems.manifold', name: 'manifold-ext', version: '2021.1.25'
    
    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
    testImplementation 'org.junit.jupiter:junit-jupiter-engine'
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
}

I tried this:

import java.math.BigDecimal;

@Extension
public abstract class ManBigDecimalExt implements ComparableUsing<BigDecimal> {
    /**
     * Supports binary operator {@code +}
     */
    public static BigDecimal plus(@This BigDecimal thiz, BigDecimal that) {
        return thiz.add(that);
    }
}

But it stated that these Manifold Annotations were not found:

@Extension
@This

What should I do?


Solution

  • Thanks for the Github page, it helped a lot! After skimming through the web page you sent me, I found the solution. Actually, in the library systems.manifold, the annotations you mentioned are not present. Add another implementation named manifold-science or manifold-ext like this,

    implementation 'systems.manifold:manifold-science:2021.1.25-SNAPSHOT'
    

    or

    implementation 'systems.manifold:manifold-ext:2021.1.25-SNAPSHOT'
    

    And, add another repository for obtaining the library,

    maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    

    Don't forget to import the libraries,

    import manifold.ext.rt.api.Extension;
    import manifold.ext.rt.api.This;
    import manifold.ext.rt.api.ComparableUsing;
    

    Hopefully, this should solve the problem :D