Résolu Compiler un mod avec des libs
-
Bonjour,
j’ai fait un mod qui utilises des libs
Tout marche très bien sur mon ide mais quand je fais le fameux “gradlew build”,
l’export ne contient plus mes librairiesMes libs sont dans le dossier libs (dans la racine de mon projet)
Voici mon build.gradle si vous voulez bien m’aiderbuildscript { repositories { jcenter() maven { url = "https://files.minecraftforge.net/maven" } mavenCentral() } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.forge' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. version = "1.0" group = "com.drastic.twitchmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TwitchMod" sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. compileJava { sourceCompatibility = targetCompatibility = '1.8' } minecraft { version = "1.12.2-14.23.5.2847" runDir = "run" // the mappings can be changed at any time, and must be in the following format. // snapshot_YYYYMMDD snapshot are built nightly. // stable_# stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // simply re-run your setup task after changing the mappings to update your workspace. mappings = "snapshot_20171003" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } dependencies { // you may put jars on which you depend on in ./libs // or you may define them like so.. //compile "some.group:artifact:version:classifier" //compile "some.group:artifact:version" // real examples //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, // except that these dependencies get remapped to your current MCP mappings //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' // for more info... // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html compile fileTree(dir: 'lib', includes: ['*.jar']) } processResources { // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' // replace version and mcversion expand 'version':project.version, 'mcversion':project.minecraft.version } // copy everything else except the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
Cdlt
DrasticLp -
Bon j’ai trouvé !
J’ai réussi avec cette config :buildscript { repositories { maven { url = 'https://files.minecraftforge.net/maven' } maven { url "https://plugins.gradle.org/m2/" } jcenter() mavenCentral() maven { url 'https://jitpack.io' } gradlePluginPortal() } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2' } } plugins{ id 'java' } apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'eclipse' apply plugin: 'com.github.johnrengelman.shadow' version = "1.0.0" group = "com.drastic.twitchmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TwitchMod-RedSkyll" sourceCompatibility = targetCompatibility = '1.8' compileJava { sourceCompatibility = targetCompatibility = '1.8' } println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { version = "1.12.2-14.23.5.2847" runDir = "run" mappings 'snapshot_20171003' } dependencies { shadow fileTree(dir: 'libs', include: ['*.jar']) } import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation task relocateShadowJar(type: ConfigureShadowRelocation) { target = tasks.shadowJar prefix = "twitchmod" } tasks.shadowJar.dependsOn tasks.relocateShadowJar reobf { shadowJar {} } processResources { inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' expand 'version':project.version, 'mcversion':project.minecraft.version } from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
#Mon Sep 14 12:28:28 PDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
-
Bonjour,
C’est normal que ton mod n’inclut pas les libs. Il faut créer un fatjar pour que le libs soit inclut, une recherche des mots clés
gradle fatjar
et éventuellementgradle shadow relocate
devrait te mettre sur la voie à suivre. -
@robin4002 a dit dans Compiler un mod avec des libs :
gradle shadow relocate
Merci !
Dans mon cas, vu que forge add en dependencies tt les .jar de mon dossier libs,
je dois mettre quoi dans relocate ‘jsp’ ? -
@robin4002
J’ai fait un fatJarbuild.gradle
buildscript { repositories { jcenter() maven { url = "https://files.minecraftforge.net/maven" } } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1' } } apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'com.github.johnrengelman.shadow' version = "1.0" group = "com.drastic.twitchmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TwitchMod" sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. compileJava { sourceCompatibility = targetCompatibility = '1.8' } minecraft { version = "1.12.2-14.23.5.2847" runDir = "run" mappings = "snapshot_20171003" } dependencies { shadow fileTree(dir: 'libs', includes: ['*.jar']) } reobf { shadowJar {} } processResources { inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' expand 'version':project.version, 'mcversion':project.minecraft.version } from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
Ca m’exporte bien mon mod mais j’ai une erreur quand je lance le jeu
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Twitch Mod (twitchmod) Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
-
Probablement car tu embarque dans ton jar une lib qui est déjà utilisé par Minecraft mais dans une autre version, d’où la nécessité de relocate.
EDIT: quoi que; slf4j ne semble pas être utilisé par Minecraft. As-tu bien installé le fichier -all.jar ?
-
@robin4002 oui, bien sûr
-
Donc essaies de relocate la bibliothèque slf4j
-
@robin4002 comment je suis censé faire ?
(je me doute qu’il faut utiliser relocate dans build.gradle mais aucune idée de comment)Edit : je tiens à préciser que mes libs sont des .jar dans /libs ^^
-
https://imperceptiblethoughts.com/shadow/configuration/relocation/#filtering-relocation
Ce n’est pas vraiment une bonne pratique d’avoir les libs dans le dossier libs. Utilises plutôt les dépendances via maven.
-
@robin4002 merci !
J’ai réussi à exporter et le jeu ne crash plus mais j’ai 2 problèmes :J’ai ce magnifique icône sur eclipse
(ça n’a pas l’air d’influer sur le jeu)Et sur minecraft (hors eclipse), le jeu n’a pas l’air de vouloir charger mes resources
Je n’ai pas non plus mettre mes libs via maven car j’ai un crash au lancement si je fais comme ça car gradle ne connait pas la fonction api() nécessaire à ma dépendance
buildscript { repositories { jcenter() maven { url = "https://files.minecraftforge.net/maven" } maven { url "https://plugins.gradle.org/m2/" } mavenCentral() } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.3' } } apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.plugin-shadow' version = "1.0" group = "com.drastic.twitchmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TwitchMod" sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. compileJava { sourceCompatibility = targetCompatibility = '1.8' } minecraft { version = "1.12.2-14.23.5.2847" runDir = "run" mappings = "snapshot_20171003" } dependencies { implementation fileTree(dir: 'libs', includes: ['*.jar']) } import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation task relocateShadowJar(type: ConfigureShadowRelocation) { target = tasks.shadowJar prefix = "twitchmod" // Default value is "shadow" } tasks.shadowJar.dependsOn tasks.relocateShadowJar reobf { shadowJar {} } processResources { inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' expand 'version':project.version, 'mcversion':project.minecraft.version } from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
#Mon Sep 14 12:28:28 PDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
-
Ah probablement que le fat jar n’inclut pas les ressources. As-tu déjà vérifié si le dossier assets est présent ou non dans le fat jar ?
api c’est pour les versions récentes de gradle, utilises
compile
à la place. -
@robin4002 bonjour,
j’ai bien vérifié et mes assets / mcmod.info sont bien dans mon jarJe pense que le problème vient de ForgeGradle car il est déprécié quand on met à jour gradle (ce que j’ai fait pour pouvoir utiliser shadow)
Malheureusement, je n’ai aucune idée de comment utiliser ForgeGradle 3.+
-
C’est presque pareil, base toi sur le mdk de forge 14.23.5.2855
-
@robin4002 d’acc
j’ai réussi mais j’ai une erreur quand je fais un gradlew setupDecompWorkspace
edit: j’ai trouvé le pourquoi mais pas la solution : le bon lien pour le userdev est : https://maven.minecraftforge.net/net/minecraftforge/forge/1.12.2-14.23.5.2847/forge-1.12.2-14.23.5.2847-userdev.jar
mais forge cherche
https://maven.minecraftforge.net/net/minecraftforge/forge/1.12.2-14.23.5.2847/forge-1.12.2-14.23.5.2847/userdev3.jarbuildscript { repositories { maven { url = 'https://files.minecraftforge.net/maven' } maven { url "https://plugins.gradle.org/m2/" } jcenter() mavenCentral() } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0' } } plugins{ id 'com.github.johnrengelman.shadow' version '5.2.0' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' version = "1.0.1" group = "com.drastic.twitchmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TwitchMod" sourceCompatibility = targetCompatibility = '1.8' compileJava { sourceCompatibility = targetCompatibility = '1.8' } println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { mappings channel: 'snapshot', version: '20171003' runs { client { workingDirectory project.file('run') // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' // Recommended logging level for the console property 'forge.logging.console.level', 'debug' mods { examplemod { source sourceSets.main } } } server { workingDirectory project.file('run') // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' // Recommended logging level for the console property 'forge.logging.console.level', 'debug' mods { examplemod { source sourceSets.main } } } data { workingDirectory project.file('run') // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' // Recommended logging level for the console property 'forge.logging.console.level', 'debug' args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') mods { examplemod { source sourceSets.main } } } } } dependencies { minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2847' shadow fileTree(dir: 'libs', include: ['*.jar']) compile group: 'com.github.twitch4j', name: 'twitch4j', version: '1.3.1' shadow group: 'com.github.twitch4j', name: 'twitch4j', version: '1.3.1' shadow group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' } import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation task relocateShadowJar(type: ConfigureShadowRelocation) { target = tasks.shadowJar prefix = "twitchmod" } tasks.shadowJar.dependsOn tasks.relocateShadowJar reobf { shadowJar {} } processResources { inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' expand 'version':project.version, 'mcversion':project.minecraft.version } from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
-
Ah mince, donc le setup forge gradle 3 pour la 1.12 est cassé
La je n’ai pas de solution
-
@robin4002 on peut fork au pire nn ?
-
Bon j’ai trouvé !
J’ai réussi avec cette config :buildscript { repositories { maven { url = 'https://files.minecraftforge.net/maven' } maven { url "https://plugins.gradle.org/m2/" } jcenter() mavenCentral() maven { url 'https://jitpack.io' } gradlePluginPortal() } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2' } } plugins{ id 'java' } apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'eclipse' apply plugin: 'com.github.johnrengelman.shadow' version = "1.0.0" group = "com.drastic.twitchmod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TwitchMod-RedSkyll" sourceCompatibility = targetCompatibility = '1.8' compileJava { sourceCompatibility = targetCompatibility = '1.8' } println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { version = "1.12.2-14.23.5.2847" runDir = "run" mappings 'snapshot_20171003' } dependencies { shadow fileTree(dir: 'libs', include: ['*.jar']) } import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation task relocateShadowJar(type: ConfigureShadowRelocation) { target = tasks.shadowJar prefix = "twitchmod" } tasks.shadowJar.dependsOn tasks.relocateShadowJar reobf { shadowJar {} } processResources { inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' expand 'version':project.version, 'mcversion':project.minecraft.version } from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } }
#Mon Sep 14 12:28:28 PDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
-
-
-