Gradle provided dependencies with Intellij

后端 未结 3 1297
感动是毒
感动是毒 2021-01-21 10:48

I\'m trying to build a Bukkit plugin. The plugin also uses exp4j. The final result needs to have the exp4j code included in the released jar but not have the Bu

相关标签:
3条回答
  • 2021-01-21 11:03

    In Gradle 2.12 and later, there is a configuration called compileOnly that has the provided semantics you are looking for.

    More about this configuration on the Gradle blog post on the subject.

    Before 2.12, you can use the nebula.provided-base plugin to create a provided configuration with all the correct semantics.

    0 讨论(0)
  • 2021-01-21 11:07

    I did find a very hacky solution. But it's so bad I feel bad posting it here :P

    1. Declare the provided dependencies as runtime dependencies
    2. Regenerate the idea files: gradle cleanIdea idea
    3. Idea should now recognise the dependences
    4. Change the provided dependencies back to provided
    5. Go into the project settings and convert all the dependencies with runtime scope to Intellij's provided scope
    6. Stuff works :) (Just don't ever regenerate the idea files)

    Obvious problems, anyone using your project has to do the same hack. And every time you regenerate the idea files, the same thing will have to be repeated.

    0 讨论(0)
  • 2021-01-21 11:16

    See Gradle issue here.

    There isn't a provided configuration in gradle, though there really should be one. The most reasonable workaround currently seems to be, to create your own configuration:

    configurations {
        provided
    }
    

    and then:

    sourceSets {
        main {
          compileClasspath += configurations.provided
        }
    }
    

    The problem with extendsFrom is that the provided dependency will end up being bundled in your distribution anyway unless if you add another explicit exclude, defeating the whole point of provided.

    Edit: To tell idea to use the provided dependencies, you could apply the 'idea' plugin and then:

    idea {
      module {
        scopes.PROVIDED.plus += [ configurations.provided ]
      }
    }
    

    see more here.

    0 讨论(0)
提交回复
热议问题