Using Maven to fill in project id, name, version etc

I’ve written a plugin messaging channel api that uses a common api across Bukkit, Bungeecord, and Sponge. GitHub - Crypnotic/MessageChannel: A plugin messaging channel wrapper aimed at keeping all channel communications in a single, uniform pipeline.

The only problem I’ve ran in to with Sponge & Forge development is that, AFAIK, there is no way to auto fill the id, name, version, etc of the plugin. Whereas in Bukkit & Bungeecord Maven can fill it into the plugin.yml & bungee.yml respectively. Is there an alternative to this in Sponge & Forge?

There’s a gradle plugin for this, although there isn’t a maven one afaik.

EDIT: Link if you’re interested: Setting Up Gradle — Sponge 7.2.0 documentation

AND here’s some documentation for the maven setup: Setting Up Maven — Sponge 7.2.0 documentation

This still doesn’t prevent me from having to fill in all of this values within the main class @Plugin annotation

There is a maven plugin which you can very easily use (unlike the entire gradle bullshit)

Add this to your build.plugins section

 <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>templating-maven-plugin</artifactId>
                <version>1.0.0</version>
                <executions>
                    <execution>
                        <id>filter-src</id>
                        <goals>
                            <goal>filter-sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

create a java-templates folder in your src directory

├───src
    ├───main
        ├───java
        ├───java-templates 

under java-templates create a standart java package(=folders) structure following your plugins’ namespace.

Assuming that you set up correctly project.version in your pom file you can now create a .java file like:

public class Version {
    public static final String VERSION = "${project.version}";
}

During the build (mvn clean package) the templating plugin replaces this variable with the version from your pom.xml

In your main plugin class you can now set the version as

@Plugin(version = Version.VERSION,....

You can use this for any maven property you have defined in your pom, not just version,… ${path.to.any.xml.element}

1 Like

This one works the other way around. You fill it in in the @Plugin annotation, and it auto sets the Gradle properties.