Solved Other plugins using my logger

Discussion in 'Spigot Plugin Development' started by MrSpomg, Sep 28, 2018.

  1. Hello!
    So my core plugin depends on other (created by me as well) which shades logback and s4j logger. This logger must be only used by the the api plugin, however, there are also another plugins which soft-depend on this logger, and so, when they found it, they use it. (NameTagEdit). How shall I do so that the shaded classes could be only used by the api or the core plugin? Thanks!
     
  2. TheJavaHacker

    Supporter

    You can't limit another plugin from utilising a dependency that you also want to use. You can either use that plugin that shares the dependency or make your own.
     
  3. But the plugin (API) shading the logger dependency has been created by me. It cannot be restricted in anyway?
     
  4. well NametagEdit is open source, could fork your own version which removes all the slf4j stuff etc
     
  5. But this is for server owners using my plugin and nametagedit, or similar.
     
  6. Senmori

    Senmori Retired Resource Staff
    Retired Patron

    Are you saying plugins are using your plugin's logger (as in the Logger you create in your plugin) or they just use log4j in general?
     
  7. They use log4j in general, but since I have it configured for my plugin it sends message with my config.
     
  8. Senmori

    Senmori Retired Resource Staff
    Retired Patron

    Yeah, then you're using log4j wrong. You don't need to configure the global logger.

    Create a logger for each class (ideally), and use that. Either way, there's no realistic way to stop someone from using your logger.
     
    • Informative Informative x 1
  9. Just relocate your shaded logger.
     
    • Winner Winner x 1
  10. Wtf that's true.

    Ok thanks! I will configure it properly!
     
  11. I'd like to relocate the whole logger and some other dependencies, and also the dependencies they shade. So what should I do? What I've thought is relocating all and then excluding my own project src. Something like this:

    Code (Text):
    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.2.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <createSourcesJar>false</createSourcesJar>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <relocations>
                            <relocation>
                                <pattern>*/*</pattern>
                                <shadedPattern>me.spomg.dependencies.</shadedPattern>
                                <excludes>
                                    <exclude>me.spomg.jdaspigotapi.*</exclude>
                                </excludes>
                            </relocation>
                        </relocations>
                    </configuration>
                </plugin>
            </plugins>
    I don't get it working. Any idea?
     
  12. you need to add <artifactSet>
    Code (Text):

    <artifactSet>
       <includes>
          <include>groupId:artifactid-tobeincluded</include>
       </includes>
    </artifactSet>
     
    then use <relocation> directive to specify where those "included" packages are relocated to.
     
  13. I don't get it working...
    Code (Text):
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <artifactSet>
                            <includes>
                                <include>*:*</include>
                            </includes>
                            <excludes>
                                <exclude>me.spomg.minecord.modules:jda</exclude>
                            </excludes>
                        </artifactSet>
                        <relocations>
                            <relocation>
                                <pattern>*/*</pattern>
                                <shadedPattern>me.spomg.minecord.modules.jda.dependencies</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>