我需要从我的依赖项创建一个胖罐子,它不会包含范围内的依赖项compileOnly
dependencies {
api 'org.slf4j:slf4j-api:1.7.26' // this must be in the jar
compileOnly 'it.unimi.dsi:fastutil:8.2.1' // this must not be in the jar
jar {
from {
configurations.compileClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我构建项目时,两个依赖项都存在于最终的 jar 文件中。我该如何从 fat jar 中排除 fastutil?
我尝试使用runtimeOnly
runtimeOnly 'it.unimi.dsi:fastutil:8.2.1' // this must not be in the jar
Run Code Online (Sandbox Code Playgroud)
但这会导致 fastutil 在编译时无法解析。
我正在运行 Java 16 和 Gradle 7.0.2。
当我尝试在 Gradle 上构建时出现以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '14.0.1'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
Run Code Online (Sandbox Code Playgroud)
我安装了 Gradle 6.3。该构建使用使用 Gradle 5.1.1 的 Gradle 包装器。我必须降级 Java 吗?
我正在尝试为其创建自定义对象HashMap并编写代码hashcode和equals方法.在添加对象时HashMap,equals方法为true并且hashcode为两个对象返回相同的值,而HashMap将两个对象添加为不同的对象.这怎么可能?以下是我的代码:
class B {
String name;
int id;
public B(String name, int id)
{
this.name=name;
this.id=id;
}
public boolean equals(B b){
if(this==b)
return true;
if(b==null)
return false;
if(this.name.equals(b.name) && this.id==b.id)
return true;
else
return false;
}
public int hashcode(){
return this.id;
}
public String toString(){
return "name: "+name+" id: "+id;
}
}
Run Code Online (Sandbox Code Playgroud)
为了测试上面的代码,我在我的主类中添加了以下内容:
HashMap<B,String> sample=new HashMap<>();
B b1 = new B("Volga",1);
B b2 = new B("Volga",1); …Run Code Online (Sandbox Code Playgroud) 我使用以下代码过滤具有以下扩展名的文件
FileFilter fileFilter= new WildcardFileFilter("*.docx");
File[] sampleFiles= filesDirectory.listFiles(fileFilter);
Run Code Online (Sandbox Code Playgroud)
但是,如果我想要相反的情况,我想排除具有此扩展名的文件。目前我有以下代码
public class FileFilter {
public static void main(String[] args) {
File dir = new File("C:\\temp\\filter-exclude");
File[] files = dir.listFiles(new ExcludeFilter());
for (File f : files) {
System.out.println("file: " + f.getName());
}
}
public static class ExcludeFilter implements java.io.FileFilter {
@Override
public boolean accept(File file) {
if (file.getName().toLowerCase().endsWith("docx")) {
return false;
}
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但不确定是否已经有这方面的课程。有这样的课吗?