Maven multi-module project and unix/lf lineEnding issue - maven-2

I am very new to Maven and running into a problem that I can't figure out. I have a multi-module project setup. In one of the sub-modules, I have some Unix bash scripts. In my assembly file, I want to build a zip file that contains all my Unix scripts with line ending of either "unix" or "lf". Every thing works as expected when I package my application at the sub-module level (scripts do have the right Unix line ending). However, when I package my application at the master project level, scripts don't end up in Unix line ending. Is there a solution for this problem ? Thanks.
Here is a sample snippet of my assembly file: (which is defined for one of my submodules at the submodule level)
<fileSet>
<directory>src/main/scripts</directory>
<outputDirectory>bin</outputDirectory>
<lineEnding>unix</lineEnding>
<fileMode>0755</fileMode>
</fileSet>

Looks like you're running into this bug: http://jira.codehaus.org/browse/MASSEMBLY-237.
Just force the assembly plugin version to 2.2-beta-3 and your problem should be solved.

Related

IntelliJ Spring Boot: How to create an executable jar

I'm trying to create an executable jar from IntelliJ.
First I got the Java Security Exception and I changed sqljdbc4-4.0 to unsigned. First problem solved.
Then I got Manifest not found. Added META-INF dir to output. Second problem solved.
Next I got the BeanCreationException (unsolved):
Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
In IntelliJ it is working.
I think the resources are not in the output. (application.properties, ...)
In which way do I add the resources or where are they stored in the jar.
I'm using gradle and on the spring boot homepage are only instructions for maven.
You should use spring-boot-maven-plugin or spring-boot-gradle-plugin, depending on your preferred build system.
EDIT:
Just run ./gradlew build
I suggest to dive into this getting started guide. It clarifies a lot of stuff for beginners.
A typical Spring boot project is a Maven project or a Gradle-Project (I only know how to do it with Maven, for Gradle see [luboskrnacs answer][1]). So you just need to run the maven targetpackageand pick the jar form the (created)target` folder
use a shell, go to the project root directory (where the pom.xml file is) and type
mvn clean package
cd target
the there is the xxx.jar file.

Using Gradle to Build an IntelliJ Module From Command Line

I understand the basic functionality of gradle, but I don't understand how to use a build.gradle file other than the one in the project's root. I have a project which contains a gradle wrapper in it's root, and a module which has it's own build.gradle file. How do I specify for gradlew to use the module's build.gradle file instead of the one in the root directory?
Specifically, I have an IntelliJ project I have uploaded to my CI server, and I am trying to setup a script to run the builds automatically.
Cheers
It looks like you have a multi-module build which only has a single module... correct?
You could include a settings.gradle which points to the module
You could declare a GradleBuild task in the root module to invoke the sub module.
A good place to look for inspiration is the java samples and the organizing build logic page in the documentation. An impressive feature of gradle is that all of the code snippets which appear in the documentation is sourced from the samples directory which is run as part of their CI build.
Happy Gradling!

logback.xml and running application from JetBrains IDEA IDE

When I develop application in IDEA, where should I place logback.xml for it to have an effect on the application?
It seems when you run/debug IDEA doesn't make any jars and doesn't invoke Maven to build something. Does it execute main() directly from compiled *.class file? If so, where can I put logback.xml so that it would have effect?
logback.xml should be available in the root directory of your CLASSPATH. When you run your application, the full CLASSPATH is printed at the very beginning. When I put logback.xml in /src/main/resources (Maven project) it works without any problem. Also putting it in /src/test/resources with logback-test.xml name has presence.
Simply run:
getClass().getClassLoader().getResource("/logback.xml");
And see whether it returns something or null.
If you are not working with Maven project, open Project structure (Ctrl + Alt + Shift + S) and add in Modules section select folder containing logback.xml and mark it as Sources (blue icon).
For me: I simply needed to re-build the project (not just re-run or re-compile the project). Changing the src\main\resources\logback.xml did not affect logback because the class loader is picking up the logback.xml that is in the target/ folder, not the /src folder. This makes sense since target is the run environment. Therefore, a build is required to transfer the new xml file over to target.

how to run only parent pom.xml in maven multi-module project

I have maven multi-modules project. At the parent level, i have some java files. And in the parent pom.xml, at the package phase i do some stuff.
Usually, when i run mvn package at parent level, the package phase of parent pom will be run and all the modules will be packaged as well.
I am looking for a way that allow me to do these (when i run mvn package):
allow me to run only paren pom.xml (the script at the package phase), not the modules. This is the 1st priority.
allow me to run paren pom.xml and some particular modules (like module 1, module 2 BUT not module 3 , module 4).
Can i use profile for those issue?
Thanks.
While I agree with the fact that you may not have optimal project structure, the answer is that Maven 2.2.1 has an option "--non-recursive" which satisfies your first requirement:
-N,--non-recursive Do not recurse into sub-projects
So something like this:
mvn --non-recursive clean compile
Why do you want to have java code on the top level? In my opinion this is not a very good idea. Have your code in the subprojects and let the top-level project be responsible for holding the general information and configuration of the entire project.
If you have some base-library code in the top-level project now, you can put it in a sub-project and set up dependencies between the projects.
Take a look at Maven parent pom vs modules pom
The nature of your question indicates that your project structure may not be optimal.

Maven adds class files of snapshot dependencies

on my Windows machine I do have several proeject that I build with maven. At the moment they are all in SNAPSHOT-State. When I build a project that relies on one of the other projects maven always adds the class files of the other projects to the jar.
If I build the project on my CI-Server this problem does not occur. Does anyone have an idea why maven adds the class files to my jar?
I'm using maven 2.2.1
When I build a project that relies on one of the other projects maven always adds the class files of the other projects to the jar.
This is not a default behavior and, if it happens, you're somehow telling Maven to do so. If you want to hunt potential discrepancies, check the effective-pom, the effective-settings, the active-profiles using the following goals on both machines:
help:effective-pom
help:effective-settings
help:active-profiles
Also double check how Maven is invoked on the CI machine (extra command line parameter, etc).