1

我有一个基于 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

我该怎么办?

4

2 回答 2

1

感谢 Github 页面,它帮助了很多!在浏览了您发送给我的网页后,我找到了解决方案。实际上,在 librarysystems.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

于 2021-10-09T16:12:05.793 回答
0

项目快速参考提供了 Manifold 的所有依赖项的链接,每个依赖项都提供了自己的设置文档。

Manifold Extensions的设置文档,您似乎正在使用:

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 编译器参数。复制/粘贴处理-Xplugin:Manifold.
  • implements ComparableUsing<BigDecimal>从您的 ManBigDecimalExt 中删除 ,因为它复制了已在歧管科学中实现的接口。另外,plus方法也有重复;已支持 BigDecimal 算术manifold-science
于 2021-10-10T01:47:30.927 回答