Skip to content

Commit

Permalink
Fix some dependency declarations failing builds
Browse files Browse the repository at this point in the history
  • Loading branch information
triphora committed Mar 14, 2023
1 parent 43faee0 commit 8ad8d01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'com.gradle.plugin-publish' version '1.1.0'
}

version = '2.7.4'
version = '2.7.5'
group = 'com.modrinth.minotaur'
archivesBaseName = 'Minotaur'
description = 'Modrinth plugin for publishing builds to the website!'
Expand All @@ -20,7 +20,7 @@ repositories {
dependencies {
compileOnly gradleApi()
compileOnly group: 'org.jetbrains', name: 'annotations', version: '+'
api group: 'dev.masecla', name: 'Modrinth4J', version: '2.0.1'
api group: 'dev.masecla', name: 'Modrinth4J', version: '2.1.0'
compileOnly group: 'io.papermc.paperweight', name: 'paperweight-userdev', version: '1.5.2'
}

Expand Down
30 changes: 6 additions & 24 deletions src/main/java/com/modrinth/minotaur/dependencies/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ProjectDependency toNew(ModrinthAPI api, ModrinthExtension ext) {
return new ProjectDependency(null, id, null, dep.getDependencyType());
} else if (this instanceof VersionDependency) {
VersionDependency dep = (VersionDependency) this;
String versionId = resolveVersionId(dep.getProjectId(), dep.getVersionId(), api, ext);
String versionId = resolveVersionId(dep.getProjectId(), dep.getVersionId(), api);
return new ProjectDependency(versionId, dep.getProjectId(), null, dep.getDependencyType());
} else {
throw new GradleException("Dependency was not an instance of ModDependency or VersionDependency!");
Expand All @@ -94,30 +94,12 @@ public static Dependency fromNew(ProjectDependency newDep) {
* @param versionId ID or version number of the project to resolve
* @return ID of the resolved project
*/
private String resolveVersionId(String projectId, String versionId, ModrinthAPI api, ModrinthExtension ext) {
attempt: try {
// First check to see if the version is simply a version ID. Return it if so.
ProjectVersion version = api.versions().getVersion(versionId).join();
private String resolveVersionId(String projectId, String versionId, ModrinthAPI api) {
try {
ProjectVersion version = api.versions().getVersionByNumber(projectId, versionId).join();
return version.getId();
} catch (Exception ignored) {
// Seems it wasn't a version ID. Try to extract a version number.
if (projectId == null) {
break attempt;
}
GetProjectVersionsRequest filter = GetProjectVersionsRequest.builder()
.loaders(ext.getLoaders().get())
.gameVersions(ext.getGameVersions().get())
.build();
List<ProjectVersion> versions = api.versions().getProjectVersions(projectId, filter).join();

for (ProjectVersion version : versions) {
if (version.getVersionNumber().equals(versionId)) {
return version.getId();
}
}
} catch (Exception e) {
throw new GradleException("Failed to resolve version \"" + versionId + "\"!", e);
}

// Input wasn't a version ID or a version number
throw new GradleException("Failed to resolve version \"" + versionId + "\"!");
}
}

0 comments on commit 8ad8d01

Please sign in to comment.