Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Keridos authored Sep 24, 2023
0 parents commit eab7deb
Show file tree
Hide file tree
Showing 27 changed files with 838 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disable autocrlf on generated files, they always generate with LF
# Add any extra files or paths here to make git stop saying they
# are changed when only line endings change.
src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# eclipse
bin
*.launch
.settings
.metadata
.classpath
.project

# idea
out
*.ipr
*.iws
*.iml
.idea

# gradle
build
.gradle

# other
eclipse
run

# Files from Forge MDK
forge*changelog.txt
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "runenv"]
path = runenv
url = https://github.com/amadornes/fg-multiproject-runenv.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Néstor Amador

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ForgeGradle Multiproject Template

This repository provides a template for multiproject development environments using ForgeGradle.

## Project structure
This template builds upon the [runenv template](https://github.com/amadornes/fg-multiproject-runenv) repo to provide the
binding logic that makes the multiproject environment work.

The built-in `examplelib` and `examplemod` projects are standard Forge MDK projects, heavily trimmed down for the sake
of simplicity, and are unaware that they exist within a multiproject environment.

## Setup
To set up a multiproject development environment, just clone this repository.
Optionally, you may delete the `.git` directory and initialize your own git repo in its place.
It is advised to keep the *runenv template* as a submodule, which allows you to easily pull new versions down the line.

## Customization
The most basic form of customization comes in the form of adding new projects to `settings.gradle`.
Just add new `include 'YourProjectName'` lines in the same place you find the predefined ones.

If you are authoring several mods that depend on each other, but you still want to be able to compile them on their own,
this template also allows it.
For example, if one of your projects depends on `fg.deobf("com.example:examplelib:1.2.3")`, you can define a
substitution in the root level buildscript: `substitute module("com.example:examplelib") using project(":examplelib")`.
This will make it so whatever depended on that artifact will now depend on the project in your dev environment instead.
Make sure to also define an exclusion for the same module in the `if` statement above it. That will ensure that
ForgeGradle doesn't try to unnecessarily resolve the artifact.

Further customization can be done by either modifying the *runenv template*, or the `project('runenv')` closure in the
root level buildscript.

## Generating runs
The run configurations for your multiproject environment should point to the *runenv template*.
You must run that project's `gen<IDE>Runs` task and use its classpath at runtime for all the projects to load.

For datagen, you may still use each project's individual runs.

## Known issues
Please check the [runenv template](https://github.com/amadornes/fg-multiproject-runenv) repository, as that will contain
the latest information regarding compatibility.

## Contributions
Pull requests adding extended feature support and bugfixes are welcome.
Please keep them simple if possible.
49 changes: 49 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1"
}

subprojects {
configurations.all {
if (it.name.startsWith("_")) {
// You must exclude the same modules you substitute here, because ForgeGradle
exclude group: "com.example", module: "examplelib"
return
}

resolutionStrategy.dependencySubstitution {
// Apply substitutions for modules your projects depend on, replacing them with another project
substitute module("com.example:examplelib") using project(":examplelib")
}

// Uncomment the following line if you are running into issues with dependency resolution.
// The reason is likely transitive dependencies bleeding into other projects and not
// being able to be resolved. Note that doing this will require you to manage certain
// kinds of dependencies (such as those needed at runtime) yourself:
//
// transitive false
}
}

project('runenv') {
ext {
mcversion = '1.19'
forgeversion = '41.1.0'
// javaversion = 17 // Defaults to 17 already
// mappings = channel: 'official', version: '1.18.2' // Defaults to mojmap for the specified MC version
// runArgs = [ ] // Arguments applied to all runs
// runProps = [ name: value ] // Properties applied to all runs
}
repositories {
// Repositories for additional runtime dependencies go here
}
afterEvaluate {
dependencies {
// This is where any additional runtime dependencies for your dev environment go
}
}
}

// Ensure the run directory is excluded from the idea module
idea.module {
excludeDirs << file("run")
}
5 changes: 5 additions & 0 deletions examplelib/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disable autocrlf on generated files, they always generate with LF
# Add any extra files or paths here to make git stop saying they
# are changed when only line endings change.
src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf
25 changes: 25 additions & 0 deletions examplelib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# eclipse
bin
*.launch
.settings
.metadata
.classpath
.project

# idea
out
*.ipr
*.iws
*.iml
.idea

# gradle
build
.gradle

# other
eclipse
run

# Files from Forge MDK
forge*changelog.txt
105 changes: 105 additions & 0 deletions examplelib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
}
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = _version
group = 'com.example'
archivesBaseName = 'ExampleLib'

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

minecraft {
mappings channel: 'official', version: _mcversion

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

runs {
client {
workingDirectory project.file('run/client')

property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'

mods {
examplelib {
source sourceSets.main
}
}
}

server {
workingDirectory project.file('run/server')

property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'

mods {
examplelib {
source sourceSets.main
}
}
}

data {
workingDirectory project.file('run/data')

property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'

args '--mod', 'examplelib', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')

mods {
examplelib {
source sourceSets.main
}
}
}
}
}

sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
}

dependencies {
minecraft "net.minecraftforge:forge:${_mcversion}-${_forgeversion}"
}

jar {
manifest {
attributes([
"Specification-Title" : "examplelib",
"Specification-Vendor" : "exampleauthor",
"Specification-Version" : "1",
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : "exampleauthor",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}

jar.finalizedBy('reobfJar')

publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
}
}
repositories {
maven {
url "file://${rootProject.projectDir}/mcmodsrepo"
}
}
}
3 changes: 3 additions & 0 deletions examplelib/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_version=0.0.1
_mcversion=1.19
_forgeversion=41.1.0
25 changes: 25 additions & 0 deletions examplelib/src/main/java/com/example/examplelib/ExampleLib.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.examplelib;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod("examplelib")
public class ExampleLib
{
private static final Logger LOGGER = LogManager.getLogger();

public ExampleLib() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
}

private void setup(final FMLCommonSetupEvent event) {
LOGGER.info("Hello from the library's preinit");
}

public static void printTheThing() {
LOGGER.info("I'm the library and I was asked to print the thing!");
}
}
25 changes: 25 additions & 0 deletions examplelib/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
modLoader="javafml"
loaderVersion="[37,)"
license="MIT"

[[mods]]
modId="examplelib"
version="${file.jarVersion}"
displayName="Example Lib"
authors="Example Author"
description='''
This is an example library
'''

[[dependencies.examplelib]]
modId="forge"
mandatory=true
versionRange="[37,)"
ordering="NONE"
side="BOTH"
[[dependencies.examplelib]]
modId="minecraft"
mandatory=true
versionRange="[1.17.1,1.18)"
ordering="NONE"
side="BOTH"
7 changes: 7 additions & 0 deletions examplelib/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"pack": {
"description": "examplelib resources",
"pack_format": 6,
"_comment": "A pack_format of 6 requires json lang files and some texture changes from 1.16.2. Note: we require v6 pack meta for all mods."
}
}
5 changes: 5 additions & 0 deletions examplemod/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disable autocrlf on generated files, they always generate with LF
# Add any extra files or paths here to make git stop saying they
# are changed when only line endings change.
src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf
25 changes: 25 additions & 0 deletions examplemod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# eclipse
bin
*.launch
.settings
.metadata
.classpath
.project

# idea
out
*.ipr
*.iws
*.iml
.idea

# gradle
build
.gradle

# other
eclipse
run

# Files from Forge MDK
forge*changelog.txt
Loading

0 comments on commit eab7deb

Please sign in to comment.