2

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?

Alexei
  • 14,350
  • 37
  • 121
  • 240
  • Firstly, are you sure that Manifold installed correctly? Did you sync your gradle files? Did the sync complete without any error? – JustinW Oct 08 '21 at 05:29
  • @JustInCoding I think Manifold is not download. I restart my IDEA, press rebuild project, but it not help. – Alexei Oct 08 '21 at 06:15
  • Did the rebuild complete without any errors? – JustinW Oct 08 '21 at 06:21
  • @JustInCoding Has errors , not found annotations Extenstion and This – Alexei Oct 08 '21 at 06:24
  • Can you please tell me from where did you look up the tutorial for these specific annotations – JustinW Oct 09 '21 at 10:33
  • @JustInCoding https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-ext#operators-by-extension-methods – Alexei Oct 09 '21 at 11:24

2 Answers2

1

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

JustinW
  • 2,567
  • 1
  • 13
  • 29
  • @JustingCoding. OK, success compile and import... but I get another error: https://stackoverflow.com/questions/69509002/cant-use-my-manifold-extension-method-in-java-gradle-project – Alexei Oct 09 '21 at 17:16
0

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.
Scott
  • 949
  • 9
  • 14
  • Not help. Same error – Alexei Oct 10 '21 at 07:54
  • Do you have *both* the `implementation` and `annotationProcessor` dependencies setup properly? Did you remove the "-SNAPSHOT" part? Did you provide the correct package name for your extension class and put it in the corresponding package hierarchy? – Scott Oct 10 '21 at 17:34
  • Yes, but it not help – Alexei Oct 10 '21 at 18:15
  • post your gradle build, or better yet, post your github project, otherwise it's difficult to guess what is wrong – Scott Oct 10 '21 at 20:01
  • I was updated my post with build.gradle – Alexei Oct 11 '21 at 06:41
  • See the update in my answer. Generally, you are missing the `-Xplugin:Manifold` compiler argument and your BigDecimal extension should not implement the interface nor should it provide the plus method because those are already provided with `manifold-science`. – Scott Oct 11 '21 at 15:31