无法在 gradle java 项目中使用 Manifold

Can't use Manifold in gradle java project

我有一个基于 JDK 11 的项目,我想在我的 java 项目中使用 Manifold (http://manifold.systems/)。

我的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"
    }
}

我试过这个:

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);
    }
}

但是它说找不到这些Manifold Annotations:

@Extension
@This

我该怎么办?

感谢 Github 页面,帮助很大!浏览了您发给我的网页后,我找到了解决方案。实际上,在库 systems.manifold 中,您提到的注释不存在。添加另一个名为 manifold-sciencemanifold-ext 的实现,

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

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

并且,添加另一个用于获取库的存储库,

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

不要忘记导入库,

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

希望这能解决问题 :D

Projects Quick Reference 提供指向所有 Manifold 依赖项的链接,每个依赖项都提供自己的安装文档。

您似乎正在使用的 Manifold Extensions setup docs

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

更新:

根据您最近的更新,您需要进行以下更改:

  • 您的 build.gradle 缺少上面指定的 Manifold 编译器参数。 Copy/Paste if/else 语句处理 -Xplugin:Manifold.
  • 从您的 ManBigDecimalExt 中删除 implements ComparableUsing<BigDecimal>,因为它复制了流形科学中已经实现的接口。此外,plus 方法也被复制; manifold-science.
  • 已经支持 BigDecimal 算法