SpongeDocs icon indicating copy to clipboard operation
SpongeDocs copied to clipboard

Question: Recommended implementation setup?

Open JBYoshi opened this issue 9 years ago • 5 comments

What's the recommended way to set up both a SpongeForge workspace and a SpongeVanilla workspace that share a single local SpongeCommon repository? Right now, I'm using a symlink in my SpongeVanilla repo to the SpongeCommon submodule of my SpongeForge repository.

Not sure which repository to post this in. I'm posting this here because it probably ought to be mentioned in the docs.

JBYoshi avatar Jul 29 '15 15:07 JBYoshi

I've had good success with both these methods:

  • Just symlink the SpongeCommon directory in one project to the SpongeCommon in the other project.
  • Set the path to SpongeCommon explicitly in the settings.gradle file to point at the other project's SpongeCommon path, this is simpler (arguably) to set up, but does mean you need to remember to not add settings.gradle to the git index when committing.

The first is a simple one-time task, but requires knowledge of symlinking (which, especially for windows users, isn't always a readily-available skill). The second is super-simple to set up but means you can't git add * which might be annoying to some.

Mumfrey avatar Jul 29 '15 15:07 Mumfrey

Thanks. I'll leave this open in case someone wants to put it in the docs.

JBYoshi avatar Jul 29 '15 16:07 JBYoshi

Bumping this to see if this is still current. If so we really should probably add it to our "Preparing for Development" pages.

Inscrutable avatar Aug 31 '18 10:08 Inscrutable

Since then, I've had problems where symlinking the submodule makes Git think the submodule was removed. Because I still need to bump submodules, that solution no longer works.

What I ended up doing was:

  • I cloned SpongeVanilla without the SpongeCommon submodule.
  • Inside the SpongeCommon directory, I added a .git file (not a directory) containing the line gitdir: relative/path/to/SpongeCommon/.git (followed by a blank ending line). This equates to a Git-only symbolic link. Nothing else is in that directory.
  • Then I added a custom init script to Gradle that redirected SpongeCommon and all of its subprojects to the location I had them. Gradle currently doesn't let you add init scripts per-project, so I added a global init script that runs any script in the current project under .gradle/jbyoshi-init.gradle (which is ignored).

SpongeVanilla-specific init script (SpongeVanilla/.gradle/jbyoshi-init.gradle in my setup):

import java.nio.file.Path

def fixProjectPaths(current, Path from, Path to) {
    Path oldDir = current.projectDir.toPath()
    if (oldDir.startsWith(from)) {
        Path newDir = to.resolve(from.relativize(oldDir)).normalize()
        current.projectDir = newDir.toFile()
        System.out.println('Changed directory for ' + current.path + ' from ' + oldDir + ' to ' + newDir)
    }
    for (child in current.children) {
        fixProjectPaths(child, from, to)
    }
}

settingsEvaluated { settings ->
    def rootPath = settings.rootProject.projectDir.toPath()
    // Adjust these paths as necessary
    fixProjectPaths(settings.rootProject, rootPath.resolve('SpongeCommon'), rootPath.resolve('../SpongeForge/SpongeCommon'))
}

Global init script (/Users/jbyoshi/.gradle/init.gradle):

def projectDir = gradle.startParameter.currentDir  // TODO search upwards (I haven't needed this yet myself)
def customInitScript = new File(projectDir, '.gradle/jbyoshi-init.gradle')
if (customInitScript.isFile()) apply from: customInitScript

JBYoshi avatar Sep 01 '18 14:09 JBYoshi

I personally keep both separated. If I'm working on either one in tandem, I just have two instances of IntelliJ to keep both projects open and do the git command line to keep both sponge commons updated.

gabizou avatar Sep 01 '18 18:09 gabizou