Setting a property for only a specific phase - maven

I want to be able to set a property for a specific maven phase. How can I do that?
For example, assume that I want to set a property like this:
<properties>
<spring.profiles.active>production<spring.profiles.active>
</properties>
only when one is executing mvn package. I know that I can manually set a property, but I want it to be automatic so it is not forgotten.

This is not possible.
But probably there is a solution for the original problem you want to solve. Please write a new question which describes the use case.

Related

Is Maven ${project.name} ever null?

I want to use ${project.name} for resource filtering. I know that this value comes from the Maven Model object. But the documentation doesn't indicate if this can ever return null.
Is a value always assigned to ${project.name} during resource filtering, even if the POM does not specify a <name>? I would prefer some authoritative reference. Thanks.
Yes, it can be, if you haven't defined it in the <name/> tag.
Why do you want to use ${project.name}, instead of ${project.artifactId}? You should be using the latter instead.

Multi Value option in Apache Nifi Processor

I was designing on my own custom processor. I added couple of simple property descriptor into it with simple non-empty validators. I was looking for a validator by which I can add multiple values into one property descriptor. Something like below.
My property descriptor will have multi value selection option.
Does anyone know how can I achieve it ?
Multi-value selection for a single property descriptor is not supported. Would be curious to better understand the use case. Now, of course you can have many properties and even support dynamically generated (at runtime) properties.
Thanks
Joe

How to push a value of an unchanged field into the target in a plugin's input parameters?

I'm deleting an instance of an entity and depending on the value of an option set in it, I wish to carry our different course of action. The problem is that the field isn't changed, hence, not provided to the plugin's target.
How can I easily tell the stupid plugin to fetch all the fields?
The way I do it now is to use pre-image but I'll be showing the plugin to some rookies and they will definitely not like it. And they won't believe me that's the way to go, for sure, because they're a cocky bunch.
Is there a work-around for that?
Using the pre-image is the suggested way in this scenario, the alternative is to instantiate a service factory in order to get an IOrganizationService and retrieve the entity using the target's Id.
It is part of the IPluginExecutionContext (of which Target is one part.) I think the beginners are confused if they think of Target as anything more than a property of IPluginExecutionContext.
It wouldn't make sense to have these values as part of Target, because then it would cause an update of the field to its current value - if you forced it into Target you would see the update in the audit details.
Thus, CRM has PreEntityImages, Target, and PostEntityImages, if Target was used the way "they" want it would not be able to differentiate between values being updated, previous values, and the final result of the entity.

How to set dynamic input dependency on gradle task

I'm working on a Gradle plugin that has a task that generates compilable Java source code. It takes as input for the code generator a "static" directory (property value) which should contain files in a special language (using a specific extent). In addition, if a particular configuration property is set to true, it will also search for files with the same extent in the entire classpath (or better, in a specific configuration).
I want to make sure that the task runs if any of its input dependencies are new.
It's easy enough to add #InputDirectory to the property definition for the "static" location, but I'm unsure how to handle the "dynamic" input dependency.
I have a property that defines the name of the configuration that would be used to search for additional files with that extent. We'll call that "searchConfiguration". This property is optional. If it's not set, it will use "compile". I also have the property that specifies whether we will search for additional files in the first place. We'll call that "inspectDependencies".
I think I could write a #Input-annotated method that returns essentially the "configurations.searchConfiguration.files" list. We'll call that "getDependencies". I think that is the basic idea. However, I don't understand what to do about "inspectDependencies". I could easily make "getDependencies" return an empty list if "inspectDependencies" is false, but is that truly the correct thing to do? It seems likely that if someone changed "inspectDependencies" from "true" to "false" after a build, the next build should run the task again.
Well, this is tentative, but I asked about this on the Gradle Forum and Mark Viera convinced me that it really should be this simple, although it requires #InputFiles instead of #Input. My particular method looks like this:
#InputFiles
def getOptionalYangClasspath() {
return inspectDependencies ? project.configurations[yangFilesConfiguration] : Collections.emptyList()
}

Doing calculations on properties

Is it possible to do string and math operations on properties in maven 2?
I have a property ${version} that has a value of something like 5.3.0-SNAPSHOT, now I'd like to extract the 5 and do some math on it, say subtract 3 from it. So my new property would get the value 2.
You may want to look at the parse-version goal of build helper maven plugin. As the example in this page indicates, once this goal is run, it makes available a bunch of propeties which can be used to do subsequent operations.
parsedVersion.majorVersion
parsedVersion.minorVersion
parsedVersion.incrementalVersion
parsedVersion.qualifier
parsedVersion.buildNumber
There is an example here (http://ronalleva.com/groovy/maven/programming/2008/01/23/using-the-groovy-maven-plugin-to-do-magic.html) which embeds groovy into your plugin. Further in the example he sets a property in the maven project.

Resources