我有一個基于 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
我該怎么辦?
uj5u.com熱心網友回復:
感謝 Github 頁面,它幫助了很多!在瀏覽了您發送給我的網頁后,我找到了解決方案。實際上,在 library 中systems.manifold,您提到的注釋不存在。添加另一個名為manifold-science或manifold-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
uj5u.com熱心網友回復:
該專案快速參考提供鏈接到所有歧管的依賴,每個提供它自己的設定檔案。
您似乎正在使用的 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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/311276.html
