Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
* @since 2024/7/20 20:31
*/
@SuppressWarnings("deprecation")

public class AetherResolver {

private static final Map<String, AetherResolver> resolverMap = Maps.newConcurrentMap();
Expand Down Expand Up @@ -95,14 +94,19 @@ public List<File> resolve(@NotNull String library, List<DependencyScope> scope,

@Override
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
// 忽略可选
if (ignoreOptional && node.getDependency().isOptional()) return false;
// 依赖传递
if (isTransitive) return true;
// 选定的主依赖必被加载
if (self) {
self = false;
return true;
}
// 子依赖传递
if (!isTransitive) return false;
// 忽略可选依赖
if (ignoreOptional && node.getDependency().isOptional()) return false;
// 依赖作用域过滤
for (DependencyScope s : scope) {
if (s.name().equalsIgnoreCase(node.getDependency().getScope())) return true;
}
return false;
}
});
Expand All @@ -113,9 +117,11 @@ public static AetherResolver of(@NotNull String repository) {
}

public static @Nullable ClassLoader inject(@NotNull File file, @Nullable List<JarRelocation> relocation, boolean isExternal) throws Throwable {
// 避免重复加载多个依赖
if (injectedDependencies.contains(file.getPath())) return null;
else injectedDependencies.add(file.getParent());
// 文件路径: group/name/version/file
// 两次获取父文件跳到 name 层, 避免重复加载同一个依赖 (的不同版本)
String path = file.getParentFile().getParentFile().getPath();
if (injectedDependencies.contains(path)) return null;
else injectedDependencies.add(path);
// 如果没有重定向规则,直接注入
if (relocation == null || relocation.isEmpty()) {
return ClassAppender.addPath(file.toPath(), PrimitiveSettings.IS_ISOLATED_MODE, isExternal);
Expand Down
Loading