31

The Maven Standard Directory Layout says that scripts should be placed in src/main/scripts in a maven project. Besides the advantages of "convention over configuration" are there any other advantages of doing it this way? I have a project that builds an executable jar-with-dependencies using the assembly plugin. There are also some useful scripts that go along with it. Are there any tools that take advantage of this layout in building something else, for example, an archive that includes the jar and these scripts in a reasonable location?

[update] In fact, I would go so far as to say that that putting scripts in src/main/scripts is disadvantageous, as far as use with the maven-assembly plugin is concerned.. It appears that EVERYTHING under /src/main (except src/main/java of course) is copied into the root directory of the jar-with-dependencies, as with src/main/resources, where this is useful. But there is no good reason to have scripts in the jar, although it does no particular harm. If, instead of placing them in src/main/scripts, one places them in src/scripts (analogously to the standard src/assembly, which also isn't included), then they are not copied into the jar and can be copied by a later run of the assembly plugin into a larger archive.

Update: It appears that we must distinguish between runtime scripts that are launched from within the java code and others which launch the jar or do other things. For the former, putting them in src/main/scripts may be appropriate. For the latter, inappropriate.

Update: I entered a bug against the maven documentation about this.

Update: The src/main/scripts directory was removed from the Standard Directory Layout documentation due to it being misleading. (Remnants however still remain in Introduction to POM as it's tied to the project.build.scriptSourceDirectory property.)

antak
  • 19,481
  • 9
  • 72
  • 80
Steve Cohen
  • 4,679
  • 9
  • 51
  • 89
  • "there is no good reason to have scripts in the jar," - What kind of script are you using in your project? Build scripts shouldn't go into the jar, but sometimes you have runtime scripts (Javascript, groovy, etc or some dsl) that you need in the jar. Since the scripts get copied, I would think tahat maybe you are only supposed to use this directory for script that you actually want in the jar. – kapex Mar 27 '15 at 15:20
  • @kapep - In my case it is a script that launches the main class of the jar (with various parameters), which clearly does not belong IN the jar. As far as your thoughts about using this directory only for scripts that you want in the jar, I would agree, but that's not what the Standard Directory Layout page says. Another possible location would be src/scripts, analogously to src/assembly in the standard layout. This directory does not get included in the jar either. – Steve Cohen Mar 27 '15 at 15:39
  • @kapep - I've updated to take into account your comments about scripts launched from the java code, which is a different case. – Steve Cohen Mar 27 '15 at 15:51
  • "Application/Library scripts" could be interpreted as _scripts that are used by the application_ - and not scripts that are used to launch/build it. But I agree, the meaning isn't really clear. Hopefully your bug report will clear things up. – kapex Mar 27 '15 at 16:40
  • 1
    Since the codehaus bugtracker went offline: This [commit](https://github.com/apache/maven-site/commit/4f33c893315f48a9122784d6da2513e5b31c43fa) solved the issue by removing the `script` directory from the documentation because apparently this directory wasn't mentioned anywhere else. – kapex Sep 29 '16 at 09:10
  • Ha! You answered this almost a year after it was closed by the "gods" as being "opinion-based". Thank you @Kapep for understanding the question. Stack Oveflow moderators slay me sometimes. Methinks the moderators have too much work on their plates to carefully read all the posts they have to moderate. – Steve Cohen Sep 29 '16 at 14:36
  • I have had a quick test, using Maven 3.1.0 + Assembly Plugin 3.1.0 . I cannot observe the behavior of "jar-with-dependencies by default copy everything under src/main/* ". May I know which version of Maven & Assmebly Plugin you used when you observe the behavior? – Adrian Shum Jan 04 '18 at 03:11

0 Answers0