MinecraftForge / ForgeGradle

Minecraft mod development framework used by Forge and FML for the gradle build system
GNU Lesser General Public License v2.1
520 stars 444 forks source link

fg.deobf ignores javadoc and sources #736

Closed Jonathing closed 3 years ago

Jonathing commented 3 years ago

The problem

Hi all! I've noticed a bit of a weird and incredibly inconvenient issue with fg.deobf wherein whenever you use it to decompile a jar from a maven, it completely ignores javadoc and source jars that might also be up in the same location on the maven repository.

Here's an example. I work on a mod with a few of my friends that requires a dependency mod we made called Structure Gel API. We recently launched a maven repository to make dependency handling for us easier, and so we've been able to add Structure Gel API as a dependency like so:

// Additional dependencies (including Minecraft) for the project)
dependencies {
    // Minecraft Forge
    minecraft "net.minecraftforge:forge:1.16.4-35.1.10".toString()

    // Structure Gel API
    compile fg.deobf("com.legacy:structure-gel:1.7.3")
}

This works great on its own, but we also have a javadoc jar and a sources jar on the same location where the main built jar is located (for context, it's right here: https://maven.moddinglegacy.com/artifactory/modding-legacy/com/legacy/structure-gel/1.16.4-1.7.3/). However they are completely ignored by fg.deobf and are never actually added to the project. To my knowledge, using compile on its own without fg.deobf does not have this problem.

Workaround (Eclipse only; very hacky)

I was able to workaround this problem in the buildscript by manually downloading the javadoc and sources jars with the Gradle Download Task, but obviously, the most idea solution would be for ForageGradle's fg.deobf dependency task to take into account potential sources and javadocs and attach them with the given dependency at hand.

This workaround only works for Eclipse because the eclipse task actually outputs a file containing all of the dependencies of the gradle project, which can then be tinkered with in the buildscript. IntelliJ doesn't do that, so you'd have to manually re-add the sources jar and javadoc jar on each gradle project refresh.

For anyone interested in this workaround, here is what I wrote. Please do take into account variable names (which are stored in gradle.properties) and URLs I used and replace them with whatever you might need. Standard Gradle buildscript stuff.

Top of the build.gradle

buildscript {
    repositories {
        maven { url = 'https://files.minecraftforge.net/maven' }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
        classpath group: 'de.undercouch', name: 'gradle-download-task', version: '4.1.1'
    }
}
apply plugin: 'net.minecraftforge.gradle' // ForgeGradle
apply plugin: 'de.undercouch.download' // Gradle Download Task

Anywhere in build.gradle

// Additional dependencies (including Minecraft) for the project)
dependencies {
    // Minecraft Forge
    minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}".toString()

    // Structure Gel API
    compile fg.deobf("com.legacy:structure-gel:${gel_version}")
}

// Download additional sources and javadoc jars
eclipse {
    classpath {
        file {
            whenMerged {
                def lib = entries.find { it.path.contains "structure-gel-${gel_version}_mapped_${mappings_channel}_${mappings_version}.jar".toString() }
                lib.sourcePath = fileReference(file("libs/structure-gel-${gel_version}-sources.jar".toString()))
                lib.javadocPath = fileReference(file("libs/structure-gel-${gel_version}-javadoc.jar".toString()))
            }
        }
    }
}

// Make sure to download Structure Gel additional files for eclipse before continuing
eclipseClasspath {
    dependsOn 'sgDownloadFiles'
}

// Download additional files for Structure Gel
task sgDownloadFiles {
    doLast {
        download {
            src "https://maven.moddinglegacy.com/artifactory/modding-legacy/com/legacy/structure-gel/${gel_version}/structure-gel-${gel_version}-sources.jar".toString()
            dest new File("libs/structure-gel-${gel_version}-sources.jar".toString())
            overwrite true
        }

        download {
            src "https://maven.moddinglegacy.com/artifactory/modding-legacy/com/legacy/structure-gel/${gel_version}/structure-gel-${gel_version}-javadoc.jar".toString()
            dest new File("libs/structure-gel-${gel_version}-javadoc.jar".toString())
            overwrite true
        }
    }
}

If there's anything else you might want me to clarify, feel free to make a comment and I'll answer as best as I can. Thanks for your time and patience!

tie commented 3 years ago

Not sure about javadoc part, but looks like sources were fixed in https://github.com/MinecraftForge/ForgeGradle/pull/746.

Jonathing commented 3 years ago

Not sure about javadoc part, but looks like sources were fixed in #746.

Yup, I think that's good enough for now. Honestly, there probably isn't a need for the javadoc jar to be renamed anyway. Thank you very much, and sorry for the late response!