0

I'm using the Build Helper Maven plugin to attach the SQL changes as an artifact of the deployment, but the plugin crashes when the extra artifact is not present.

Failed to install artifact org.test.app1:app1:sql:1.2.1: app1/src/main/database-source/1.2.1/dba.sql (No such file or directory) -> [Help 1]

The SQL file is present for most app versions, but not on all of them, since minor app versions may not include SQL changes. The directory structure for the SQL files includes their versions separately as shown below:

src/
  main/
    database-source/
      1.0.0/
        dba.sql
      1.2.0/
        dba.sql
      1.2.1/
        -- no "dba.sql" file here since there aren't SQL changes in this version
      1.3.0/
        dba.sql

The Build Helper plugin configuration I'm using is:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>src/main/database-source/${project.version}/dba.sql</file>
            <type>sql</type>
          </artifact>
        </artifacts>
      </configuration>
    </execution>
  </executions>
</plugin>

I read about the <skipAttach> tag, but don't understand how to use it.

How can I silently skip the extra artifact when the file is not present (as in version 1.2.1 above)?

Joe DiNottra
  • 836
  • 8
  • 26
  • Why are you attaching via buildhelper and not simply put the into `src/main/resources`? – khmarbaise Jan 24 '20 at 18:10
  • @khmarbaise I think the content of `src/main/resources` would be included in the WAR file (for the WebSphere guy) and I don't need that. The SQL file must go to the DBA guy, a totally separate dpmt, so the WAR and the SQL file must be packaged separately. I may be wrong, though. – Joe DiNottra Jan 24 '20 at 18:12
  • Maybe [How do I activate a Maven profile if a file does NOT exist?](https://stackoverflow.com/q/30649044/592355) helpful? (accordingly, you can also "activate when exists"..) – xerx593 Jan 24 '20 at 18:14
  • @xerx593 I just tried but it says that "expressions are not supported during profile activation". I used ` src/main/database-source/${project.version}/dba.sql `. Maybe something has changed since 2015. – Joe DiNottra Jan 24 '20 at 18:19
  • Then you should simply make a separate module and create a tar/tar.gz file from it...or simply a jar file which contains only the sql files ....and if you simply attach the files they will be deployed each separate file which makes it very uncomfortable to handle... – khmarbaise Jan 24 '20 at 18:24
  • i see, @JoeDiNottra ...that's a problem/blocker ...we could try to workaround this, but i feel there's a cleaner/less intrusive solution... haven't you "just tried" `true` (within configuration tag)? – xerx593 Jan 24 '20 at 18:40
  • ...and the current state is: you comment it in/out build/version wise...? (also for CI?) – xerx593 Jan 24 '20 at 18:47
  • 1
    Wouldn't it be better to manage database changes (which probably all have to be applied in the right order) by a tool like Flyway? – J Fabian Meier Jan 24 '20 at 19:01
  • 1
    @xerx593 I tried that skipAttach with "true" and it always skips it, even when present. I try adding some logic to it (like the "exists" tag) but crashes. – Joe DiNottra Jan 24 '20 at 19:45
  • ...then it is at least "more elegant" to un-/comment 1 property only than the whole plugin (release/version wise) – xerx593 Jan 24 '20 at 20:02
  • @xerx593 Thanks, the `skipAttach` tag was the solution. A bit tricky, but I was able to automate it fully. Thanks again. – Joe DiNottra Jan 26 '20 at 02:00

0 Answers0