SBT: Exclude class from Jar

后端 未结 2 1099
感动是毒
感动是毒 2020-12-14 10:21

I am converting a legacy jar project to SBT and for strange reasons that are not easily solved, this project comes with \"javax/servlet/Servlet.class\" insi

2条回答
  •  醉梦人生
    2020-12-14 10:44

    Each task declares the other tasks and settings that it uses. You can use inspect to determine these inputs as described on Inspecting Settings and in a recent tutorial-style blog post by John Cheng.

    In this case, the relevant task used by packageBin is mappings. The mappings task collects the files to be included in the jar and maps them to the path in the jar. Some background is explained on Mapping Files, but the result is that mappings produces a value of type Seq[(File, String)]. Here, the File is the input file providing the content and the String is the path in the jar.

    So, to modify the mappings for the packageBin task, filter out the paths from the default mappings that you don't want to include:

    mappings in (Compile,packageBin) ~= { (ms: Seq[(File, String)]) =>
      ms filter { case (file, toPath) =>
        toPath != "javax/servlet/Servlet.class"
      }
    }
    

    mappings in (Compile,packageBin) selects the mappings for the main package task (as opposed to test sources or the packageSrc task).

    x ~= f means "set x to the result of applying function f to the previous value of x". (See More About Settings for details.)

    The filter drops all pairs where the path corresponds to the Servlet class.

提交回复
热议问题