Categories
Uncategorized

Conditional maven modules

This is a little something that’s now caught me out a few times. Quite often, I’ll have a project with a parent POM, and a module that I only care about in certain circumstances. So I naturally do this.

  
  
    
      foo-core
      foo-webapp
    
    
      
        dist
        
          foo-dist
        
      
    
  

Unfortunately, this can interact badly with the release plugin. Unless that profile is activated during release, the module won’t have it’s version updated. So the next time you use that profile, it’ll break.

The correct solution is to “push down” the profile into the foo-dist module. i.e.

  
  
    foo
    foo-parent
    1.0-SNAPSHOT
    
      foo-core
      foo-webapp
      foo-dist
    
  

  
  
    foo-dist
    
      foo
      foo-parent
      1.0-SNAPSHOT
    
    
      
        dist
        
      
    
  

That way, foo-dist is always available, but is a noop unless the profile is activated. But it does ensure that the release plugin (and also the versions plugin) know that it’s there.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s