I have a regular Maven project. I would like to set certain properties/variables in the JAR when building using mvn package, so that certain information can be picked up from individual JAR files.
For example, I could use:
mvn package -DbuildId=200
... and I would like to see this information stored (buildId = 200) stored in some file generated by maven. I know for a fact that certain properties are stored by Maven at build-time (for example, the files in META-INF/maven).
Is this possible without modification of the POM file, and without adding extra plugins? If so, what arguments do I need to pass?
Related
I wonder if the maven-checkstyle-plugin only check files within the /src directories of a project or multi-module project.
I do have a maven project where I don't have /src directories but loads of *.yaml, *.wsdl, *.json and *.xsd files and do not know if they are gonna checked with this plugin as well.
Yes, you can activate more checks for more filetypes in more locations. However...
You are probably using the check goal of the maven-checkstyle-plugin. As you can see, the default resource includes is only set to **/*.properties. Change it to anything you like.
To answer your seconds question, where checkstyle will look for sources and resources, there's an option for this in the same page:
<sourceDirectories> List 2.13 Specifies the location of the source directories to be used for Checkstyle. Default value is ${project.compileSourceRoots}.
However, the standard checks included in checkstyle do not include a lot of checks for files other than .java or .properties files. You might want to take a look at other plugins, like the spotless-maven-plugin's prettier configuration.
I am trying to create a docker image from within maven which includes artifacts from a different maven project. But the examples I have copied do not appear to be working.
I think the problem here is I do not really understand how assemblies work and so am asking for help on what I want to do here. I have set up a contrived simple example of what I am trying to do here:
https://github.com/sodved/java-docker-demo/tree/0.0.1-0
pom.xml
sod-java/pom.xml
sod-java/src/main/java/sodved/Sod.java
sod-docker/pom-depency.xml
sod-docker/pom.xml
sod-docker/src/main/docker/setup.sh
sod-docker/src/main/docker/Dockerfile
sod-docker/src/main/docker/run.sh
So my project has two modules:
sod-java which builds an executable jar (which just writes a file to /tmp/sod.txt)
sod-docker which creates a java alpine image with Dockerfile
setup.sh is run when building the image. It runs the java to create the /tmp/sod.txt
run.sh is the default command writes the content of the /tmp/sod.txt file
I have tried two approaches to the inline <assembly> so far:
https://github.com/sodved/java-docker-demo/blob/0.0.1-0/sod-docker/pom-depency.xml Was my first attempt. Using dependecySet in the assembly. But I noted that the dependency was not even included in the /target folder (I assume because there is no actual java code to compile in sod-docker, so the dependencies were not copied).
https://github.com/sodved/java-docker-demo/blob/0.0.1-0/sod-docker/pom.xml Was my second attempt. It first explicitly copied the artifact into /target folder (which worked). Then used file in the assembly to try and copy the file.
In both cases I do not see the jar file copied anywhere by the assembly or in the tar file which the docker plugin creates and so I get an error when attempting to reference the jar in a Dockerfile COPY command.
I know the example is a bit contrived. But its simple and fitting with the standard way we do things at work. So I do not have a lot of flexibility in respect to tools, layouts etc.
The real case is used to build database images. Get base image, run java code to manipulate database, save as new image to be used downstream.
TLDR:
How can I specify a groupId, artifactId, version and have the corresponding artifact included in my docker image. The docker source itself contains no java.
OK, have figured it out.
The issue was that the pom.xml specified some external configuration
<external>
<type>properties</type>
<prefix>docker</prefix>
<mode>override</mode>
</external>
But as the doco here (http://dmp.fabric8.io/#property-configuration) says, this means the <build> configuration (including my assembly) in the pom.xml will be ignored. I am not sure why our standard uses the external configuration, will chase up our ops people on that. But removing this <external> section and everything works.
Is it possible in java program to read class files in jar present in maven repository without downloading. I need the methods and class names of the jar present in the pom file of maven.But is there any way i get to list out all the methods and class available for the jar specified in pom file without downloading the jars
No.
You need to read these classes/methods from somewhere. There is no separate pre-compiled metadata in the Maven repo, so the only way to get this information is to actually have the class files. Which come in a JAR. Which you have to download.
I'm using Springboot and would like to replace the property values in the org.apache.catalina.util ServerInfo.properties file when building the project. The file is buried in a dependent jar: tomcat-embed-core-8.5.2.3.jar. So my app jar will have the replaced values but the tomcat-embed-core-8.5.2.3.jar in the repos will remain as is.
I looked at Maven filters but that looks like it only works if the property file is reachable within my project only (like in src/main/resources), not if the file is in another jar. Is that right?
What's the best way to do this? A Maven solution or something simpler is okay.
I use maven-assembly plugin to create a zip file for a release in my target folder. This package with dynamic name includes a configuration file;
/target/dailyrelease-4234.zip/cd/lib/conf/wrapper.conf
Now I also use maven-dependency plugin's build-classpath goal to output the dependencies as a string.
I want to write this output string to the configuration file created by the assembly plugin
I have 2 problems:
1- How can I access this conf file in the dynamic named zip?
2- I want to add some extra .jar paths to that string created by maven dependency plugin, but it only copies the names from local repository. is there a way to modify this output, or show dependency plugin to use another folder to pick the jar names and not from local repository?
Or even better make the creating dependency names task as a part of assembly-plugin so I dont need to access and modify that zip anymore.
1 - It sounds like your mechanism for dynamically generating that number '4234' exists outside of Maven, and you're trying to figure out how to access that number from within Maven, correct?
If so, I suggest using the buildnumber-maven-plugin which generates a number which you can then access from within Maven via the ${buildNumber} property.
2 - I suggest switching your callout from dependency:build-classpath to dependency:list -DoutputFile=xyz.txt. The latter gives you a cleaner output of just groupId/artifactId/version which should be easy to edit.
Or better yet... Do the above, and simply use <phase> configuration to ensure dependency:list gets called before the assembly plugin runs (typically at the end of package phase), and ensure the resulting output file sits somewhere that the assembly plugin will pick it up.
Hope that helps.