Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Sep 6, 2024
2 parents bda6010 + 61b445c commit 37ddb70
Show file tree
Hide file tree
Showing 35 changed files with 1,167 additions and 295 deletions.
1 change: 1 addition & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"extends": [
"github>neoforged/actions:renovate_preset"
],
"baseBranches": ["main", "/^\\d+\\.x/"],
"customManagers": [
{
"customType": "regex",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3

- name: Run build
run: ./gradlew build
run: ./gradlew build neoForgeIdeSync
working-directory: ./testproject

- name: Ensure clean, build and test work in the same run
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
java: 17
pre_gradle_tasks: test
gradle_tasks: 'publish publishPlugins'
version_labels: -beta, -stable
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
MAVEN_USER: ${{ secrets.MAVEN_USER }}
Expand Down
22 changes: 22 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This document describes the breaking changes made across major versions of ModDevGradle.
For a full list of changes, and in which versions they were introduced,
please refer to the changelog, which can be found on the [project page](https://projects.neoforged.net/neoforged/moddevgradle).

## ModDevGradle 2
The breaking changes in this major version should not affect most projects.
Nonetheless, every single breaking change is documented here, along with a suggested fix.

- Changes to access transformer and interface injection data publishing.
- `accessTransformers.publish` and `interfaceInjectionData.publish` syntax was changed.
- `accessTransformers.published` and `interfaceInjectionData.published` were removed.
- This publishing feature was broken in ModDevGradle 1, and these changes were made to fix it.
- To fix: Refer to the [README](README.md#publication-of-access-transformers) for documentation of the new syntax.
- Parchment: Specifying only the Minecraft version or only the mapping version will now fail.
- This is meant to catch usage mistakes.
- Run `beforeTask`s do not run on IDE project sync anymore.
- To run a task on sync, use `neoForge.ideSyncTask <task>`.
- Removal of `dependency` and `extendsFrom` inside the `neoForge.mods {}` block.
- These functions generally do not work, and were removed to reduce confusion.
- `sourceSet <sourceSet>` should be used instead. If this is not sufficient, please open an issue.
- `mods` cannot contain the same source set multiple times.
- This is meant to catch usage mistakes.
86 changes: 82 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Check the NeoForged Project Listing for [latest releases](https://projects.neoforged.net/neoforged/ModDevGradle).

If you are updating to a new major version of the plugin, refer to the [list of breaking changes](BREAKING_CHANGES.md).

## Features

- Uses the latest Gradle best practices and is compatible with Gradle 8.8
Expand Down Expand Up @@ -106,6 +108,37 @@ neoForge {
}
```

## Common Issues

### Clicking "Attach Sources" does nothing when viewing a Minecraft class (IntelliJ IDEA)
Sometimes IntelliJ gets into a state where clicking "Attach Sources" while viewing a decompiled Minecraft class
will not work.

Reloading the Gradle Project and then clicking "Attach Sources" again will usually fix this problem.

### Task `idePostSync` not found (IntelliJ IDEA)
This error typically happens when switching to ModDevGradle from another plugin with an `idePostSync` task.
This can be fixed by unregistering the task in IntelliJ IDEA, as follows:

<details>
<summary>Click to expand</summary>

1. Open the Gradle tool window on the right, and right-click the Gradle project.

![](docs/idePostSync1.png)

2. Click on `Tasks Activation`.

![](docs/idePostSync2.png)

3. Select the `idePostSync` task and delete it using the `-` button.

![](docs/idePostSync3.png)

4. Sync the Gradle project again.

</details>

## More Configuration

### Runs
Expand Down Expand Up @@ -396,10 +429,10 @@ even if dependency management has been overridden.
Access Transformers are an advanced feature allowing mods to relax the access modifiers on Minecraft classes,
fields, and methods.

To use this feature, you can place an access transformer data file at `src/resources/META-INF/accesstransformer.cfg`,
To use this feature, you can place an access transformer data file at `src/main/resources/META-INF/accesstransformer.cfg`,
adhering to the [access transformer format](https://docs.neoforged.net/docs/advanced/accesstransformers/).

When you use the default file location, you do not need to configure anything.
**When you use the default file location, you do not need to configure anything.**

If you'd like to use additional or different access transformer files, you can modify the paths MDG reads them from
by setting the `accessTransformers` property.
Expand All @@ -410,16 +443,42 @@ by setting the `accessTransformers` property.
The elements are in the same format that `project.files(...)` expects.

```
```groovy
neoForge {
// Pulling in an access transformer from the parent project
// (Option 1) Add a single access transformer, and keep the default:
accessTransformers.from "../src/main/resources/META-INF/accesstransformer.cfg"
// (Option 2) Overwrite the whole list of access transformers, removing the default:
accessTransformers = ["../src/main/resources/META-INF/accesstransformer.cfg"]
}
```

In addition, you can add additional access transformers to the `accessTransformers` configuration using normal
Project dependency syntax in your dependencies block.

#### Publication of Access Transformers
Optionally, access transformers can be published to a Maven repository so they are usable by other mods.
To publish an access transformer, add a `publish` declaration as follows:
```groovy
neoForge {
accessTransformers {
publish file("src/main/resources/META-INF/accesstransformer.cfg")
}
}
```

If there is a single access transformer, it will be published under the `accesstransformer` classifier.
If there are multiple, they will be published under the `accesstransformer1`, `accesstransformer2`, etc... classifiers.

To consume an access transformer, add it as an `accessTransformer` dependency.
This will find all the published access transformers regardless of their file names.
For example:
```groovy
dependencies {
accessTransformer "<group>:<artifact>:<version>"
}
```

### Interface Injection

Interface injection is an advanced feature allowing mods to add additional interfaces to Minecraft classes and interfaces
Expand All @@ -434,7 +493,7 @@ Since this feature only applies at development time, you do not need to include
`build.gradle`
```groovy
neoForge {
interfaceInjectionData = files("interfaces.json")
interfaceInjectionData.from "interfaces.json"
}
```

Expand All @@ -450,6 +509,25 @@ neoForge {
In addition, you can add additional data-files to the `interfaceInjectionData` configuration using normal
Project dependency syntax in your dependencies block.

#### Publication of Interface Injection Data
The publication of interface injection data follows the same principles as the publication of access transformers.

If there is a data file, it will be published under the `interfaceinjection` classifier.
If there are multiple, they will be published under the `interfaceinjection1`, `interfaceinjection2`, etc... classifiers.

```groovy
// Publish a file:
neoForge {
interfaceInjectionData {
publish file("interfaces.json")
}
}
// Consume it:
dependencies {
interfaceInjectionData "<group>:<artifact>:<version>"
}
```

## Advanced Tips & Tricks

### Overriding Platform Libraries
Expand Down
32 changes: 29 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ base {
archivesName = "moddev-gradle"
}
gradleutils.version {
tags {
label = "beta"
cleanMarkerLabel = "stable"
}
branches.suffixBranch()
}
project.version = gradleutils.version
logger.lifecycle("ModDevGradle version ${gradleutils.version}")

changelog {
from '0.1'
// For fine-grained changelog publication control
from '2.0'
// For fine-grained changelog publication control.
// Otherwise, the changelog would get published alongside the "xxx.gradle.plugin" artifact too which we don't want.
disableAutomaticPublicationRegistration()
}

Expand Down Expand Up @@ -85,14 +91,25 @@ configurations {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "not-wanted-publication"))
}
}
changelog {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "changelog"))
}
project.components.findByName("java").addVariantsFromConfiguration(it) { }
}
}

dependencies {
compileOnly gradleApi()
compileOnly "com.intellij:annotations:9.0.4"
testCompileOnly "com.intellij:annotations:9.0.4"
shaded "com.google.code.gson:gson:2.11.0"
implementation "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.1.8"
shaded "net.neoforged:EclipseLaunchConfigs:0.1.11"
shaded "net.neoforged:VscLaunchConfigs:1.0.8"
shaded("net.neoforged:JarJarMetadata:0.4.2") {
exclude group: 'org.slf4j'
}
Expand Down Expand Up @@ -185,6 +202,14 @@ test {
useJUnitPlatform()
}

artifacts {
changelog(createChangelog.outputFile) {
builtBy(createChangelog)
setClassifier("changelog")
setExtension("txt")
}
}

publishing {
repositories {
maven {
Expand Down Expand Up @@ -251,7 +276,8 @@ public class MojangRepositoryFilter {
public static void filter(org.gradle.api.artifacts.repositories.RepositoryContentDescriptor filter) {
${artifactList.collect { " filter.includeModule(\"${it.group}\", \"${it.module}\");" }.join('\n')}
}
}"""
}
"""
output.get().asFile.write(clazz)
}
}
Expand Down
Binary file added docs/idePostSync1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/idePostSync2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/idePostSync3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ public class MojangRepositoryFilter {
public static void filter(org.gradle.api.artifacts.repositories.RepositoryContentDescriptor filter) {
filter.includeModule("argo", "argo");
filter.includeModule("ca.weblite", "java-objc-bridge");
filter.includeModule("com.fasterxml.jackson.core", "jackson-annotations");
filter.includeModule("com.fasterxml.jackson.core", "jackson-core");
filter.includeModule("com.fasterxml.jackson.core", "jackson-databind");
filter.includeModule("com.github.oshi", "oshi-core");
filter.includeModule("com.github.stephenc.jcip", "jcip-annotations");
filter.includeModule("com.google.code.gson", "gson");
filter.includeModule("com.google.guava", "failureaccess");
filter.includeModule("com.google.guava", "guava");
filter.includeModule("com.ibm.icu", "icu4j");
filter.includeModule("com.ibm.icu", "icu4j-core-mojang");
filter.includeModule("com.microsoft.azure", "msal4j");
filter.includeModule("com.mojang", "authlib");
filter.includeModule("com.mojang", "blocklist");
filter.includeModule("com.mojang", "brigadier");
Expand All @@ -21,6 +26,10 @@ public static void filter(org.gradle.api.artifacts.repositories.RepositoryConten
filter.includeModule("com.mojang", "patchy");
filter.includeModule("com.mojang", "realms");
filter.includeModule("com.mojang", "text2speech");
filter.includeModule("com.nimbusds", "content-type");
filter.includeModule("com.nimbusds", "lang-tag");
filter.includeModule("com.nimbusds", "nimbus-jose-jwt");
filter.includeModule("com.nimbusds", "oauth2-oidc-sdk");
filter.includeModule("com.paulscode", "codecjorbis");
filter.includeModule("com.paulscode", "codecwav");
filter.includeModule("com.paulscode", "libraryjavasound");
Expand Down Expand Up @@ -48,6 +57,8 @@ public static void filter(org.gradle.api.artifacts.repositories.RepositoryConten
filter.includeModule("net.java.jinput", "jinput-platform");
filter.includeModule("net.java.jutils", "jutils");
filter.includeModule("net.minecraft", "launchwrapper");
filter.includeModule("net.minidev", "accessors-smart");
filter.includeModule("net.minidev", "json-smart");
filter.includeModule("net.sf.jopt-simple", "jopt-simple");
filter.includeModule("net.sf.trove4j", "trove4j");
filter.includeModule("org.apache.commons", "commons-compress");
Expand All @@ -73,6 +84,7 @@ public static void filter(org.gradle.api.artifacts.repositories.RepositoryConten
filter.includeModule("org.lwjgl.lwjgl", "lwjgl-platform");
filter.includeModule("org.lwjgl.lwjgl", "lwjgl_util");
filter.includeModule("org.lz4", "lz4-java");
filter.includeModule("org.ow2.asm", "asm");
filter.includeModule("org.ow2.asm", "asm-all");
filter.includeModule("org.slf4j", "slf4j-api");
filter.includeModule("oshi-project", "oshi-core");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@

import org.gradle.api.file.ConfigurableFileCollection;

import javax.inject.Inject;
import java.util.function.Consumer;

/**
* Holds data files (such as ATs) to be used or exposed.
*/
public abstract class DataFileCollection {
private final Consumer<Object> publishArtifactCallback;

@Inject
public DataFileCollection(Consumer<Object> publishArtifactCallback) {
this.publishArtifactCallback = publishArtifactCallback;
}

/**
* Add the given paths to the {@linkplain #getFiles() file collection}.
* <p>
* Using this method replaces any previously present default value.
* Please note that {@code src/main/resources/META-INF/accesstransformer.cfg} is automatically
* included for access transformers, if it exists.
*/
public void from(Object... paths) {
getFiles().from(paths);
}

/**
* Add the given paths to the {@linkplain #getPublished() published file collection}.
* <p>
* Using this method replaces any previously present default value.
* Configures the given files to be published alongside this project.
* This can include files that are also passed to {@link #from}, but is not required to.
* For allowed parameters, see {@link org.gradle.api.artifacts.dsl.ArtifactHandler}.
*/
public void publish(Object... paths) {
getPublished().from(paths);
public void publish(Object artifactNotation) {
publishArtifactCallback.accept(artifactNotation);
}

/**
* {@return the files this collection contains}
*/
public abstract ConfigurableFileCollection getFiles();

/**
* {@return the files that should be published and that can be consumed by dependents}
*/
public abstract ConfigurableFileCollection getPublished();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public class InternalModelHelper {
public InternalModelHelper() {
}

public static Configuration getModConfiguration(ModModel modModel) {
return modModel.getConfiguration();
}

public static String nameOfRun(RunModel run, @Nullable String prefix, @Nullable String suffix) {
return StringUtils.uncapitalize((prefix == null ? "" : prefix)
+ StringUtils.capitalize(run.getName())
Expand Down
Loading

0 comments on commit 37ddb70

Please sign in to comment.