How to compile only changed parts of gwt modules? - eclipse

We decided to use gwt modules in our application about 1 week ago. We use gwt-maven-eclipse trio and we already configured phases and goals. Also we are doing context deploying to decrease development and testing time.
BUT;
When we package or tomcat:deploy our application, gwt modules are re-compiling(including unchanged ones).
<set-property name="user.agent" value="gecko1_8"></set-property>
<extend-property name="locale" values="en_UK"></extend-property>
I already set these properties up here to speed up compiling time but this is not what i want exactly...
I also configured maven lifecycle mapping in eclipse to fire gwt:compile process-resources resources:testResources when any resources change. But it blocks eclipse and that was not helpful about compiling time either.
This is gwt-maven-plugin configuration in pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<!--
Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org
-->
<configuration>
<runTarget>A.jsp</runTarget>
<runTarget>B.jsp</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
</configuration>
</plugin>
Any idea to help me?

gwt-maven-plugin tries (hard) to avoid recompiling modules when the code hasn't changed, but even that takes a bit of time (still less than re-compiling the module; and unfortunately if it detects the module needs to be recompiled, it adds up to the GWT compile time).
If you know you don't need gwt:compile, you can pass -Dgwt.compiler.skip=true to your Maven build to skip the goal and keep "running" your previously compiled code. Similarly, if you know you need gwt:compile, you can pass -Dgwt.compiler.force=true to bypass the "up-to-date check".

Related

Overwriting application.conf using Maven and generating jar file

I have a Scala app (v2.13) created using Maven v3. My resources path is:
src -> main -> resources -> application.conf and aplication.prod.conf
When I generate the JAR file for production, I want to take configuration resources from application.conf, but being overwriten by application.prod.conf.
I can not found a solution for that, all founded examples are for Play framework or previous maven versions.
The JAR file is generated using maven package cmd.
application.prod.conf file
include "application.conf"
# override default (DEV) settings
http {
host = "99.999.999.9"
port = 1111
}
The following example doesn't works for me, because from target path I get only the JAR file to move it on production:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete file="${project.build.outputDirectory}/application.conf"/>
<copy file="src/main/resources/application.prod.conf"
tofile="${project.build.outputDirectory}/application.conf"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
Few options here:
If your application.prod.cont is static and gets shipped with jar, why cant you have a logic in the code which loads appropriate app conf based on the environment app is getting executed
Is it a typesafe config, if so, while running in prod you can pass -Dconfig.resource=/application.prod.conf java command line argument
or application.prod.conf is not shipped with jar then you can pass -Dconfig.file=/path/to/application.prod.conf
Maven has a concept of phases (we're talking about the phase package here to be precise) which are logical places in the life cycle where the plugins can be invoked. Some plugins, like the one that creates the jar, for example, are associated to phases automatically (out-of-the-box), others you define explicitly and associate with the phase (like maven-antrun-plugin which is executed during the phase package as you've showed in the code snippet).
With that in mind, Is it possible that the file is attempted to get copied after the jar was packaged, so that the antrun plugin is invoked after the artifacts were packaged into the jar?
If so, the easiest solution will be moving it to one phase before, for example prepare-package:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>prepare-package</phase> <!-- Note the change here -->
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete file="${project.build.outputDirectory}/application.conf"/>
<copy file="src/main/resources/application.prod.conf"
tofile="${project.build.outputDirectory}/application.conf"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
Assuming you have maven 3 (there is no maven version 4 yet so it might be a typo), the information about which phases are available in maven here
Having said that, probably its not a good idea to "bake" the configuration file of production into the artifact, two issues here:
Your source code contains the information about production - hosts, ports, maybe even sensitive information like passwords or keys - this shouldn't really happen
From the point of view of build, your artifact is coupled to concrete environment, which is also considered a bad practice basically.
The techniques to resolve this are beyond the scope of the question but at least you've been warned :)

Spring REST Docs maven continuous build?

I was going through this tutorial https://www.youtube.com/watch?v=k5ncCJBarRI&t=1443s
Around 1:07:30 the author mentioned about "Gradle has continuous build" later on was able to detect changes in the test and automatically regenerate asciidoc. I was wondering if anyone knows how to set this up in maven?
I have looked through docs in spring and asciidoctor plugin, but was not able to find anything related to this.
I was able to get maven to re-render html when ever there is a change in index.adoc by changing <goal> from process-asciidoc to auto-refresh. However, this does not watch the change in the Test.
Question
Is there a way to tell Maven to watch our test files and re-compile when changes are made?
POM.XML
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.7.1</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>auto-refresh</goal>
</goals>
<configuration>
<sourceDocumentName>index.adoc</sourceDocumentName>
<backend>html</backend>
<attributes>
<snippets>${project.build.directory}/generated-snippets</snippets>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
Thank you.
This is not a continuous build solution but it works similarly. However, the process does take some time because it essentially re-packages the project everytime there is a change... May not be ideal for some use cases...
I found a plugin that watches files. https://github.com/fizzed/maven-plugins
Change the watch directory to where your test files. Changed the goal from compile to package.
Watcher will execute mvnw: package when a change is detected. Then the asciidoctor maven plugin will re-package the project.
Add this to your plugin
<plugin>
<groupId>com.fizzed</groupId>
<artifactId>fizzed-watcher-maven-plugin</artifactId>
<version>1.0.6</version>
<configuration>
<touchFile>target/classes/watcher.txt</touchFile>
<watches>
<watch>
<directory><directory>src/test/[your test package]</directory></directory>
</watch>
</watches>
<goals>
<goal>package</goal>
<!-- <goal>compile</goal> -->
</goals>
<profiles>
<profile>optional-profile-to-activate</profile>
</profiles>
</configuration>
</plugin>
Maven does not have an equivalent of Gradle's continuous build. If you want changes in the tests to be detected and to trigger recompilation of the tests and execution of all of the tasks that depend (directly or indirectly) on the compiled test classes, you'll have to use Gradle.

export AspectJ project as jar and use in another application

I am writing an Aspect in Mavenised project. PROJECT_A
Now I want to use the PROJECT_A.jar in PROJECT_B which is non mavenised.
And in PROJECT_B i want to use the annotaition which I have written using the aspect in PROJECT_A .
I tried exporting PROJECT_A.jar - with aspectJ Plugin as follows. But when i use it in PROJECT_B - my annotation does not works as expected.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
I am new to the use of AspectJ and I am not getting how to do it without maven in PROJECT_B.
Please help , any help is appreciated :)
First of all, upgrade to AspectJ Maven 1.9.
Then mavenise project B! This enables you to you can use AspectJ Maven plugin to weave the aspects into your other module, even after compilation. This is called binary weaving. Please read the plugin documentation, especially the info about parameters aspectLibraries and weaveDependencies, depending on which approach you want to pursue.
Alternatively, start your JVM with -javaagent:/path/to/aspwctjweaver.jar and use the AspectJ weaving agent for load-time weaving (LTW). But do not forget then to also provide a LTW configuration via META-INF/aop.xml.
Either way, you have options. But both require you to read some documentation or at least search this site for examples.

Maven Incremental Compilation under Eclipse

I've recently converted a big (and ugly) legacy project to Maven. It is a really really huge project (~2.7M lines of code, and a nice mix of java, jsp, js, and even VBS scripts) and is not well structured. Everything is located under a single Maven artifact (and thus a single Eclipse project).
Even with that bad structure, it used to be less or more manageable from Eclipse (even if a bit slow), but now, since it is Mavenized, every single change made to source code triggers an almost full rebuild of the code base (and 2.7M LoC take something like 10 minutes to finish), which is really unusable on a daily basis.
I've found the following bug report related to maven-compiler-plugin, unable to have an incremental compilation: https://issues.apache.org/jira/browse/MCOMPILER-205, and I'm quite confident that this is the root of our performance issues.
Have you any workaround? Do you know of a maven-compiler-plugin version not impacted with that issue? Or a setting in Eclipse which could help? Any other idea?
Thanks
The incremental compiler in Eclipse (ecj, used by the JDT) totally overrides the compiler used by command line Maven builds. Any maven-compiler-plugin or javac issue should be discarded as irrelevant. I would expect m2e/Maven to have no significant impact on a single project workspace, as big as it is. Obviously since you're seeing the opposite behavior, something is apparently slowing down the Maven builder.
Since you use jsp and js files, my guess this is a war project. If you're using the Eclipse Java EE distribution, one thing you can try is to disable the m2e-wtp integration, see if it makes any difference. Go to Preferences > Maven > Java EE Integration and uncheck Enable Java EE Configuration.
If that doesn't help (or doesn't apply to your set up), another thing you could try would be to disable Maven resource processing during incremental builds. In your pom.xml, try adding:
<profiles>
<profile>
<id>m2e</id>
<!-- This profile is only activated when building in Eclipse with m2e -->
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<versionRange>
[1.0,)
</versionRange>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
There's a chance it might break something else, but at least that should help determine whether resource processing is the culprit here.
Anything else will require a deeper analysis, I suggest you open a ticket to https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2E
Disable automatic build is the only option you have. Just build when you are interested in the artifacts.
You did not say what goals you are calling maven with. Maybe it would already be enough if you do not run all tests using -DskipTests (or even not compile them by using -Dmaven.test.skip=true), or if not willing to skip those introduce profiles to run just the necessary tests.
Since you are telling it's a legacy project I suspect that changing the project structure into a multi-module maven project is out of scope. You can then try if you can speed up using parallel builds (using -T 4 (4 threads) or -T 2C (2 threads per core).

Replace Maven Site Plugin with GWT Compile Plugin

I have successfully set up a few projects which use Maven to automatically deploy the Maven-generated site to the gh-pages branch of their git repository. GitHub then serves these files at a public URL on a personal subdomain. I'm looking to utilize this functionality to serve a rich client-side only GWT application.
I have modified my pom.xml to compile the GWT application to the target/site/ directory. The two main goals I am still attempting to achieve are:
How do I prevent the standard Maven site plugin from running during the site phase?
What is required so gwt:compile executes during the site phase?
A goal can be bound to a phase by specifying a new execution for the plugin. I'm assuming you've got some custom stuff you need to make most of this work correctly, so I'm just going to focus on what should work to bind a plugin goal to a particular phase.
<plugin>
<artifactId>gwt-maven-plugin</artifactId>
...
<executions>
<execution>
<id>gwt-site</id>
<phase>site</phase><!-- phase to bind to -->
<goals>
<goal>compile</goal><!-- goal to run in that phase -->
</goals>
<configuration>
<!-- Your magic configuration stuff goes here -->
</configuration>
</execution>
<!-- Possible other executions might be defined here -->
</executions>
</plugin>
Preventing the default maven site from being run is more interesting, as it is a phase, with a variety of goals bound to it. The standard site:site goal can be prevented from running in the site phase by explicitly specifying an execution with no goals. This may vary slightly from maven 2 to 3, so I'm going to be a little general here. Take a look at your build logs to see what is currently specified in terms of execution id, group/artifact id to correct possible oversights in my example:
<plugin>
<artifactId>maven-site-plugin</artifactId>
...
<executions>
<execution>
<phase>site</phase>
<goals></goals><!-- This is empty to indicate that no goals should be run in this phase -->
</execution>
</executions>
</plugin>