Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update source/plugin/project/gradle to api-8 #888

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/plugin/buildsystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ for the Sponge projects and provides the best integration for Sponge plugins.
Gradle
======
Gradle_ uses Groovy_ or Kotlin_ based scripts for configuring projects. A Gradle_ project typically consists of a
``build.gradle`` file in your project's root directory, which tells Gradle_ how to build the project.
``build.gradle`` or a ``build.gradle.kts`` file in your project's root directory, which tells Gradle_ how to build
the project.

.. tip::
Refer to the `Gradle User Guide`_ for the installation and a general introduction of concepts used in Gradle_. If
Expand Down
121 changes: 63 additions & 58 deletions source/plugin/project/gradle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ Setting Up Gradle

.. _using-spongegradle:

.. warning::
These docs were written for SpongeAPI 7 and are likely out of date.
`If you feel like you can help update them, please submit a PR! <https://github.com/SpongePowered/SpongeDocs>`__

Using SpongeGradle
==================

Expand All @@ -21,85 +17,95 @@ only need to update your plugin version in one file.
version together with SpongeGradle_. :ref:`The Gradle section of the build systems page <gradle-setup>` explains how
to setup Gradle on your computer.

.. tip::
The `Sponge plugin template <https://github.com/SpongePowered/sponge-plugin-template/>`__ is a `Template repository <https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template>`__
that demonstrate SpongeGradle.

Below is a simple template that should be usable for most plugins. **Make sure to replace the group with the group ID
you have chosen before.**

.. code-block:: groovy
.. code-block:: kotlin

plugins {
id 'java'
id 'org.spongepowered.plugin' version '0.11.3'
r"""`java-library`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r"""?

id("org.spongepowered.gradle.plugin") version "2.0.1"
}

// This may not be required, but has solved issues in the past
compileJava.options.encoding = 'UTF-8'

// TODO: Change the following to match your information
group = 'com.example'
version = '1.0.0-SNAPSHOT'
description = 'Here lies an example plugin definition'
group = "com.example"
version = "1.0.0-SNAPSHOT"

repositories {
jcenter()
mavenCentral()
}

dependencies {
compile 'org.spongepowered:spongeapi:8.0.0'
sponge {
apiVersion("8.0.0")
license("CHANGEME")
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
plugin("example") {
description("Just testing things...")
entrypoint("org.spongepowered.example.Example")
}
}

val javaTarget = 8 // Sponge targets a minimum of Java 8
ImMorpheus marked this conversation as resolved.
Show resolved Hide resolved
java {
sourceCompatibility = JavaVersion.toVersion(javaTarget)
targetCompatibility = JavaVersion.toVersion(javaTarget)
}

tasks.withType(JavaCompile::class).configureEach {
options.apply {
encoding = "utf-8" // Consistent source file encoding
if (JavaVersion.current().isJava10Compatible) {
release.set(javaTarget)
}
}
}

These few lines handle most settings you would normally do manually:

* Basic Gradle Java setup
* Set your project to compile with Java 8
* Add Sponge's Maven repository (and Maven Central)
* Set up a plugin with the project name in lower case as **plugin ID**
* Automatically includes the project name, description and :doc:`version <../project/version-numbers>` in
:doc:`/plugin/plugin-meta`.

Manually setting the plugin ID
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, the Gradle plugin will configure your **plugin ID** with project name (in lowercase) you have configured.
If you want to use a custom **plugin ID** and still use the :doc:`/plugin/plugin-meta` integration you can change it
manually:

.. code-block:: groovy

sponge {
plugin {
id = 'pluginidgoeshere'
}
}

Overriding defaults
~~~~~~~~~~~~~~~~~~~

By default, the Gradle plugin will contribute the **plugin name**, **plugin version**, and **description** automatically
to :doc:`/plugin/plugin-meta` with defaults defined in the project properties. It is also possible to override these if
you want to specify them manually:

.. code-block:: groovy
.. code-block:: kotlin

sponge {
plugin {
meta {
name = 'Example Plugin'
version = '1.0.0-SNAPSHOT'
description = 'This is an example plugin'
url = 'http://www.example.com/'
}
apiVersion("8.0.0-SNAPSHOT")
license("CHANGEME")
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
}

You can also remove a default value entirely:

.. code-block:: groovy

sponge {
plugin {
meta {
name = null
description = null
plugin("example") {
displayName("Example")
entrypoint("org.spongepowered.example.Example")
description("Just testing things...")
links {
homepage("https://spongepowered.org")
source("https://spongepowered.org/source")
issues("https://spongepowered.org/issues")
}
contributor("Spongie") {
description("Lead Developer")
Inscrutable marked this conversation as resolved.
Show resolved Hide resolved
}
dependency("spongeapi") {
loadOrder(PluginDependency.LoadOrder.AFTER)
optional(false)
}
}
}
Expand All @@ -114,18 +120,17 @@ Without SpongeGradle
Generally, everything necessary to compile a Sponge plugin using Gradle can be done by simply adding the SpongeAPI
dependency to your project:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not as true anymore -- you'd have to manually write out a metadata file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


.. code-block:: groovy
.. code-block:: kotlin

repositories {
jcenter()
maven {
name = 'sponge-repo'
url = 'https://repo.spongepowered.org/repository/maven-public/'
mavenCentral()
maven("https://repo.spongepowered.org/repository/maven-public/") {
name = "sponge"
}
}

dependencies {
compile 'org.spongepowered:spongeapi:8.0.0'
compileOnlyApi("org.spongepowered:spongeapi:8.0.0")
}

.. _SpongeGradle: https://github.com/SpongePowered/SpongeGradle
.. _SpongeGradle: https://github.com/SpongePowered/SpongeGradle