Scala + Maven + IntelliJ IDEA project setup

To create a Scala project using Maven to manage dependencies in IntelliJ IDEA, you first need to install the Scala plugin: File -> Preferences (Settings) -> Plugins Search Scala in the Marketplace Install it and restart IntelliJ IDEA Next, let’s create a regular Java + Maven project: File -> New -> Project Select Maven -> […]

READ MORE

Maven import static constant cannot find symbol

Suppose you have a class with constants: And you made the static import of this constant in another class: Everything looks good, and IDEA does not show any mistakes (in fact, there are really no errors in code). But Maven suddenly failed building project with cannot find symbol error. This situation can arise because there […]

READ MORE

Error while calling a method on a Groovy class

You may encounter an error when compiling your project that looks like this: It is not at all clear what class are meant. If you work with IntelliJ IDEA – this is the reason. Sometime it parses maven build/compile logs incorrectly, so the second part of the exception was lost. Compile manually through the terminal […]

READ MORE

How to add files to META-INF with Maven

Suppose you need to add some_dir/your_file.txt to META-INF using Maven, so that the final path looks like this: To do this, you need to create a META-INF/some_dir folders in the src/main/resources directory, and put there your_file.txt file: Once compiled, Maven will move META-INF/some_dir/your_file.txt from resources to the right place without deleting the existing files in […]

READ MORE

Get Maven artifact version at runtime

Let’s imagine that we need to get the value of a certain Maven property in Java code. First, let’s create a text file with any name, for example version.txt in the src/main/resources folder: Now let’s add the following block to pom.xml: Now, when building, Maven will replace the construction ${project.version} in the file with the […]

READ MORE

Determine versions of dependencies of library Maven

Imagine you need to determine the version of Apache commons-lang dependency in ZooKeeper 3.6.2. The easiest way to do this is to find the artifact page in the mvn repository. For ZooKeeper 3.6.2: https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper/3.6.2.  On the page, you need to find the Compile Dependencies section, and find the required dependency there. In our case, the commons-lang 2.6 dependency […]

READ MORE

Failed to deploy artifacts: Could not find artifact Maven

When you try to execute the mvn deploy command, you may encounter the error: The error could actually means (thanks to randomsimon):  That is, maven cannot find the repository at the specified url. Check, that the url of the repository is correct, and in general it exists and specified.  A repository url can be specified via […]

READ MORE

Exclude package from Maven-PMD and Findbugs

Suppose, that you need to exclude the package from the maven-pmd-plugin, or you need to exclude the package from findbugs-maven-plugin.  maven-pmd-plugin Pmd definition in project pom.xml: Pmd configuration file pmd-exclude.xml: findbugs-maven-plugin Findbugs definition in project pom.xml: Findbugs configuration file findbugs-exclude.xml:

READ MORE