Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to skip in Maven plugin #865

Closed
ahaeber opened this issue Aug 22, 2018 · 18 comments · Fixed by #911
Closed

Add configuration to skip in Maven plugin #865

ahaeber opened this issue Aug 22, 2018 · 18 comments · Fixed by #911
Assignees
Milestone

Comments

@ahaeber
Copy link

ahaeber commented Aug 22, 2018

In multi-module projects usually the parent POM is used to specify plugin and dependency versions to be used in child modules. Then, there are build plugins that are not desired to be enabled for all modules. Therefore it has become a common practice by Maven plugin to support a 'skip' configuration item. If skip = true then the plugin should skip that module. Then we can for example set skip = true as default and enable it (skip = false) for modules that need that plugin.

So it would be awesome if the jib-maven-plugin also could support such a 'skip' configuration.

@coollog
Copy link
Contributor

coollog commented Aug 24, 2018

Hi @ahaeber , thanks for the feature suggestion! Adding discuss label to invite others to comment on this as well.

@coollog coollog added discuss question User inquiries labels Aug 24, 2018
@alephnot0
Copy link

For local development workflow, are you assuming a team would use this plugin to replace local development? It definitely makes sense to not skip during a CI build, however I could see skipping the push to a docker repository when doing local development, especially if the tag is overwritten. Are there any examples of jib working for a team of a couple of developers?

@ahaeber
Copy link
Author

ahaeber commented Aug 25, 2018 via email

@loosebazooka
Copy link
Member

Ideally a module wouldn't have jib on it if it is not using it (using skip is a hack workaround to Maven config). Why not just use pluginManagement at the root level and then either bind the jib task to lifecycle phase 'package' (or something) or use module specific executions (-pl on commandline)

@vonnagy
Copy link

vonnagy commented Aug 28, 2018

I am not sure that adding a skip option is a hack since it is a standard for many Maven plugins. As the example by @ahaeber pointed out, one might have a multi-module project that a build could be done by a simple mvn package. If there were a skip option, then default configurations could also be added in the parent pom file and only overwritten in child modules that need to.

Just like dependencies, it would be nice to configure a plugin in the parent pom and then utilize it only in the projects that need it.

@darthbinamira
Copy link

For the reason given by @ahaeber, the point raised by @loosebazooka IMHO is a cleaner approach. You can still define the plugin in the parent pom via pluginManagement and then use it only in modules that need it.

But... there may be other scenarios where this is useful. Although you can still argue with running this only to a specific maven lifecycle and avoid the skip config.

@loosebazooka
Copy link
Member

So you can configure it in the parent and use it only on the children, using pluginManagement: https://maven.apache.org/pom.html#Plugin_Management. You can still do common configuration in the parent as you would like, and you wouldn't have to reference the plugin at all on modules that don't use it.

If the simple case that you are running mvn package, you bind the jib goal to the package phase (you can even go as far as to unbind the jar/war goal) and it all works the same.

Perhaps hack is overly aggressive in this situation, but applying the plugin everywhere and then disabling it selectively seems like a less meaningful pattern than only enabling it when necessary.

Perhaps I'm missing something though?

@ahaeber
Copy link
Author

ahaeber commented Aug 28, 2018 via email

@darthbinamira
Copy link

darthbinamira commented Aug 28, 2018 via email

@ahaeber
Copy link
Author

ahaeber commented Aug 28, 2018 via email

@darthbinamira
Copy link

Ahhh got it. Can you instead bind the package lifecycle in your web module with the plugin, that way you don't have to run with 'mvn package jib:build'. That is causing to run the plugin in all the modules.

See https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#bind-to-a-lifecycle

@ahaeber
Copy link
Author

ahaeber commented Aug 28, 2018

Hm.. so this is how the plugin is configured:

parent-pom

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>0.9.9</version>
        <configuration>
          <from>
            <image>openjdk:10-jre-slim</image>
          </from>
          <container>
            <jvmFlags>-Djava.security.egd=file:/dev/./urandom</jvmFlags>
            <args>--debug</args>
          </container>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

library-module
(nothing related to Jib plugin)

app-module

<build>
  <plugins>
    <plugin>
      <groupId>com.google.cloud.tools</groupId>
      <artifactId>jib-maven-plugin</artifactId>
      <executions>
        <execution>
          <id>latest</id>
          <!--<phase>package</phase>-->
          <phase>none</phase>
          <goals>
            <goal>build</goal>
          </goals>
          <configuration>
            <to>
              <image>${docker.registry}/${docker.image.prefix}/${project.artifactId}:latest</image>
            </to>
          </configuration>
        </execution>
        <execution>
          <id>version</id>
          <!--<phase>package</phase>-->
          <phase>none</phase>
          <goals>
            <goal>build</goal>
          </goals>
          <configuration>
            <to>
              <image>${docker.registry}/${docker.image.prefix}/${project.artifactId}:${project.version}</image>
            </to>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

As you can see I've tried binding to phase 'package' but that didn't help. Actually nothing in the app-module's pom.xml matters here because the build fails in the library-module before the app-module is processed by Maven. And many Maven plugins support a skip configuration property to handle this.

@darthbinamira
Copy link

Except for the commented package phase, I don't see anything wrong with your configs. Can you uncomment and remove the other none phase.

When running from the root dir, just do 'mvn package'. That should not run the jib plugin on your library module.

@loosebazooka
Copy link
Member

loosebazooka commented Aug 28, 2018

Yes, @darthbinamira's #865 (comment) is what you want. Just mvn package. Since maven wants everything defined on the command line to run on all modules.

If you wanted to run jib:build from the command line, you would be required to use the -pl flag to directly reference a single (or comma separated list of) modules (cli reference here). If you are not building all modules using a single command, I believe you need to install the package to correctly reference it. Might need to play around with that a little.

$ mvn install -pl lib-module && mvn prepare-package jib:build -pl app-module

@loosebazooka
Copy link
Member

Having said all that, skip might make sense for non-(jar/war) maven builds. Perhaps having everyone bend maven around is the wrong way to make builds easier. We should just add it in and let people do whatever.

@ahaeber
Copy link
Author

ahaeber commented Aug 28, 2018

Oh great, when I bind the executions to the package phase it works :)
However, it would be a bit more optimal if I could put the execution binding into the parent-pom, but I think it will fail in all jar-modules then. But at least I can do "mvn package" and get the images I need built now.

@darthbinamira
Copy link

@ahaeber Glad to hear it works for you now! :)

@loosebazooka Yeah true, there may be other scenarios as well, I just can’t think of one off the top of my head.

@coollog
Copy link
Contributor

coollog commented Sep 27, 2018

Hi @ahaeber @alephnot0 @vonnagy @darthbinamira , we have released version 0.9.11 with the skip parameter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants