Can't use Manifold in gradle java project

715 Views Asked by At

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?

2

There are 2 best solutions below

1
JustinW On BEST ANSWER

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

6
Scott On

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']
    }
}

Update:

Based on your recent update, you need to make the following changes:

  • Your build.gradle is missing the Manifold compiler argument specified above. Copy/Paste the if/else statement dealing with -Xplugin:Manifold.
  • Remove the implements ComparableUsing<BigDecimal> from your ManBigDecimalExt as it duplicates the interface already implemented in manifold-science. Additionally, the plus method is also duplicated; BigDecimal arithmetic is already supported with manifold-science.