Home > Blockchain >  Can't use Manifold in gradle java project
Can't use Manifold in gradle java project

Time:10-10

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

My build.gradle:

dependencies {
    implementation 'org.projectlombok:lombok:1.18.18'
    implementation "io.vavr:vavr:0.10.3"
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'

    // https://mvnrepository.com/artifact/systems.manifold/manifold
    implementation group: 'systems.manifold', name: 'manifold', version: '2021.1.25'

    // Add manifold to -processorpath for javac
    annotationProcessor group: 'systems.manifold', name: 'manifold', 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'
}

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?

CodePudding user response:

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 like this,

implementation 'systems.manifold:manifold-science: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

CodePudding user response:

The Projects Quick Reference supplies links to all of Manifold's dependencies, each supplying its own setup docs.

The setup docs for Manifold Extensions, which you appear to be using:

plugins {
  id 'java'
}

group 'com.example'
version '1.0-SNAPSHOT'

targetCompatibility = 11
sourceCompatibility = 11

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

configurations {
    // give tests access to annotationProcessor dependencies
    testImplementation.extendsFrom annotationProcessor
}

dependencies {
    implementation 'systems.manifold:manifold-ext-rt:2021.1.25'

    testCompile 'junit:junit:4.12'
    // Add manifold to -processorpath for javac
    annotationProcessor group: 'systems.manifold', name: 'manifold-ext', version: '2021.1.25'
}

if (JavaVersion.current() != JavaVersion.VERSION_1_8 &&
    sourceSets.main.allJava.files.any {it.name == "module-info.java"}) {
    tasks.withType(JavaCompile) {
        // if you DO define a module-info.java file:
        options.compilerArgs  = ['-Xplugin:Manifold', '--module-path', it.classpath.asPath]
    }
} else {
    tasks.withType(JavaCompile) {
        // If you DO NOT define a module-info.java file:
        options.compilerArgs  = ['-Xplugin:Manifold']
    }
}

 
  • Related