Skip to content

Commit 20a6684

Browse files
committed
plugin-development: Require specifying minecraftVersion for runServer
1 parent 8a1e8b8 commit 20a6684

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

plugin-development/src/main/java/org/spongepowered/gradle/plugin/SpongePluginExtension.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class SpongePluginExtension implements MetadataContainerConfiguration {
4646

4747
// Dependency management
4848
private final Property<SpongePlatform> platform;
49+
private final Property<String> minecraftVersion;
4950
private final Property<String> apiVersion;
5051
private final Property<Boolean> injectRepositories;
5152

@@ -58,6 +59,7 @@ public SpongePluginExtension(final ObjectFactory factory) {
5859
this.plugins = factory.domainObjectContainer(PluginConfiguration.class);
5960

6061
this.platform = factory.property(SpongePlatform.class).convention(SpongePlatform.VANILLA);
62+
this.minecraftVersion = factory.property(String.class);
6163
this.apiVersion = factory.property(String.class);
6264
this.injectRepositories = factory.property(Boolean.class);
6365
}
@@ -95,6 +97,14 @@ public void platform(final SpongePlatform platform) {
9597
this.platform.set(platform);
9698
}
9799

100+
protected Property<String> minecraftVersion() {
101+
return this.minecraftVersion;
102+
}
103+
104+
public void minecraftVersion(final String minecraftVersion) {
105+
this.minecraftVersion.set(minecraftVersion);
106+
}
107+
98108
protected Property<String> apiVersion() {
99109
return this.apiVersion;
100110
}

plugin-development/src/main/java/org/spongepowered/gradle/plugin/SpongePluginGradle.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,35 @@ public void applyToProject(
9898
final TaskProvider<JavaExec> runServer = this.createRunTask(spongeRuntime, sponge);
9999

100100
project.afterEvaluate(a -> {
101-
if (sponge.apiVersion().isPresent()) {
101+
if (sponge.minecraftVersion().isPresent() && sponge.apiVersion().isPresent()) {
102102
// TODO: client run task
103103
/*project.getLogger().lifecycle("SpongeAPI '{}' has been set within the 'spongeApi' configuration. 'runClient' and 'runServer'"
104104
+ " tasks will be available. You may use these to test your plugin.", sponge.version().get());*/
105105

106106
spongeRuntime.configure(config -> {
107+
final String minecraftVersion = sponge.minecraftVersion().get();
107108
final String apiVersion = sponge.apiVersion().get();
108109

110+
config.getAttributes().attribute(
111+
SpongeVersioningMetadataRule.MINECRAFT_TARGET,
112+
minecraftVersion
113+
);
114+
109115
config.getAttributes().attribute(
110116
SpongeVersioningMetadataRule.API_TARGET,
111117
generateApiReleasedVersion(apiVersion)
112118
);
113119
});
114120
} else {
115-
project.getLogger().info("SpongeAPI version has not been set within the 'sponge' configuration via the 'version' task. No "
116-
+ "tasks will be available to run a client or server session for debugging.");
121+
if (!sponge.minecraftVersion().isPresent()) {
122+
project.getLogger().info("Minecraft version has not been set within the 'sponge' configuration via the 'minecraftVersion' task. No "
123+
+ "tasks will be available to run a client or server session for debugging.");
124+
}
125+
126+
if (!sponge.apiVersion().isPresent()) {
127+
project.getLogger().info("SpongeAPI version has not been set within the 'sponge' configuration via the 'version' task. No "
128+
+ "tasks will be available to run a client or server session for debugging.");
129+
}
117130
runServer.configure(t -> t.setEnabled(false));
118131
}
119132
if (sponge.injectRepositories().get()) {
@@ -184,13 +197,14 @@ private void addApiDependency(final SpongePluginExtension sponge) {
184197

185198
private NamedDomainObjectProvider<Configuration> addRuntimeDependency(final SpongePluginExtension sponge) {
186199
this.project.getDependencies().getComponents().withModule("org.spongepowered:spongevanilla", SpongeVersioningMetadataRule.class);
200+
this.project.getDependencies().getAttributesSchema().attribute(SpongeVersioningMetadataRule.MINECRAFT_TARGET).getCompatibilityRules().add(ApiVersionCompatibilityRule.class);
187201
this.project.getDependencies().getAttributesSchema().attribute(SpongeVersioningMetadataRule.API_TARGET).getCompatibilityRules().add(ApiVersionCompatibilityRule.class);
188202
return this.project.getConfigurations().register("spongeRuntime", conf -> {
189203
conf.defaultDependencies(a -> {
190204
final Dependency dep = this.project.getDependencies().create(
191205
Constants.Dependencies.SPONGE_GROUP
192206
+ ":" + sponge.platform().get().artifactId()
193-
+ ":+:universal");
207+
+ ":" + sponge.minecraftVersion().getOrElse("") + "+:universal");
194208

195209
a.add(dep);
196210
});

0 commit comments

Comments
 (0)