I have a maven project that contains some Kotlin source files and some web resources (HTML/CSS). During the compile phase, the Kotlin source is compiled to JavaScript and ends up in the build output location, along with some other folders that I am not familiar with.
I would like a build step that occurs after the compile is finished that will copy my resources and compiled output and dependencies (kotlin.js) into a folder with the correct hierarchy that I deploy or debug.
I know how to copy the resources into the build output folder, but the build output folder appears to have some other files in it that are auto-generated by maven which I do not want to deploy.
Ideally, I would also like the clean phase to delete this destination directory.
Related
I have a legacy app that I'm porting from Ant to Maven. My Maven build works fine for the main project, which I've moved into the standard Maven directory layout (*.java files in /src/main/java/) and it outputs the compiled classes into /target/classes/ as neat as you could wish. These are packaged in a .war file.
However, the project also has a class outside of the folder hierarchy, indeed outside of the web application, that contains scripts that run via cron job. Let's say it's /cronjobs/MyClass.java. I need that class to be compiled and output to /target/cronjobs/MyClass.class and zipped up as part of the resulting .war file, in its /cronjobs/ folder.
Can Maven do this? I know it's possible to change the default "src" directory and "target" directory, but I don't know if (or how) it's possible to run a separate, parallel compile step for just one class.
I can move the source file, of course, if it's easier to compile it with the other classes and then move it later (maybe with the WAR plugin?) but I definitely need the compiled MyClass.class file in the /cronjobs/ directory of the .war.
I'd split the project in 2 parts, webapp as war and cronjobs as jar. Maven knows about multi-module format and it is somewhat the best way to go forward and decouple the webapp from non-webapp code.
Previously we made a Gradle project in Intellij and all the gradle files were there under the project. However, we have now moved the files in this project to a sub folder, but the Gradle files aren't being recognised. The picture below is the new folder set up where our code from the original project is now in the server folder (where the Gradle files are). When I mark the src folder (under server) as the Sources Root, that is when the dependencies from Gradle aren't recognised.
I figured out that the correct way to go is actually to separate out the client/server folder into two separate modules.
I am trying to create a maven-plugin that generates new files based on a template file (basically using the FreeMarker language). I can successfully generate the files if I run the maven plugin from the directory of my maven-plugin project since my plugin accesses the template file based on a relative path.
However, if I try to run the plugin in some other java project directory, I cannot find the template file. I do not want to copy the templated file into the new java project.
I searched around to see if the maven plugin can access files within itself when another project is using the plugin but wasn't successful. Most of the documentation refers to accessing the java project files, and not the maven-plugin files.
Is this even possible or is there a better approach/workaround to tackle the problem?
Edit (Directory structure):
Maven-Plugin (FileGenerator):
src
--main
--java
--FileGenerator.java (references the TemplateFile based on the path to the root project)
TemplateFile
If I run the plugin as a standalone, I am able to generate new files based on the TemplateFile. I achieve the following structure
Maven-Plugin (FileGenerator):
src
--main
--java
--FileGenerator.java
TemplateFile
NewFile1
NewFile2
However, if I run the plugin in another directory (such as part of another java project) with the command mvn myplugin:mypluginplugin:1.0-SNAPSHOT:build
Another Java Project
src
--main
--java
--AnotherFile.java
pom.xml
I get an error mentioning that the TemplateFile cannot be found. Is there a way for the plugin to reference the TemplateFile regardless of where it is run at?
Ideal Output After running plugin
Another Java Project
src
--main
--java
--AnotherFile.java
pom.xml
NewFile1
NewFile2
I have two (Java) projects, a library and an executable which uses the library. The two projects reside in subfolders of the same folder but I don't want to add anything (like settings.gradle) in the root folder (they come from different git repositories, thus, I cannot have the files in the common parent source controlled). Here is my layout:
lib - has some runtime dependencies (from the maven repo)
app - depends on lib and has some (different) runtime dependencies
The goal is to produce a folder (Gradle's build\libs is good enough), containing a jar file and a lib subfolder with all runtime dependencies. What is the best approach with Gradle? Here is the result I am looking for:
app\
build\
libs\
app.jar
lib\ - all dependencies are here
With ant for instance, I bring everything together when building the executable (referencing the lib's source code via ../lib/). That's somewhat ugly, but get's the job done. Ideally, I would think that it's more flexible to have the lib build as a dependency, when building the executable, just adding another jar to the app's lib subfolder.
Thanks in advance
You can put your root build.gradle file and the settings.gradle file in a folder named master next to your lib and app folder:
lib - has some runtime dependencies (from the maven repo)
app - depends on lib and has some (different) runtime dependencies
master - root build.gradle file + settings.gradle file
gradle looks for a master folder when searching for a settings.gradle file
I have an existing library that I am building in Eclipse and have added the Maven nature to my project using m2e to add dependencies. When I convert it to a Maven project, my existing source directory (and my bin) become normal folders. Is there a reason for this? I am new to Maven, so I am likely doing something wrong, just not sure what...
My project structure is as follows:
workspace
project
src (in build path)
resources (in build path)
bin (output dir)
I tried both "mvn eclipse:eclipse" and right click on project -> Configure -> Convert to Maven Project, and both removed my src and resources folders from my build path, and after changing the structure to the below, changed the output to target/test-cases. Even if I manually adjust the build path and output, my dependencies don't resolve.
workspace
project
src (no longer in build path)
resources (no longer in build path)
bin (no longer output)
target (new output dir)
test-cases (empty)
I think you have the following structure when working with Eclipse (without Maven):
/workspace
/project1
.project
/src
/bin
But Maven want to use the following structure
/workspace
/project1
.project
pom.xml
/src
/main
/java
/resources
/test
/java
/target
/classes
/test-classes
and so on. So it is normal, that the folder src is no more directly a source folder for Eclipse, but now there are src/main/java, src/main/resources, ...
So it would be easier in the beginning to start with a new Maven project, and move your original sources to the directories they should belong to. Maven has a long tradition with its "convention over configuration", to deviate from that is possible. Have a look at the answer to "Handling unconventional source directory ..." to fix this.