im building a web-application with GWT and Maven. For the unit-tests, i'm using the gwt-test-utils Framework.
I tried it as described in the tutorial (https://github.com/gwt-test-utils/gwt-test-utils/wiki/Unit-testing-basics).
When i run my unit tests in eclipse, all works fine. (The "gwt-test-utils.properties" file is at "test/META-INF/gwt-test-utils.properties")
But if i'm try to run the tests with maven, the test failes because it cant find the "gwt-test-utils.properties" file in the META-INF folder.
Do I need to explizit specify this folder/file in Maven?
Edit:
I solved it by my self. I had to add the "test" directory to the "resources", too.
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>test</directory>
</testResource>
</testResources>
Now it works..
Related
I have a following project structure
bin
start.sh
db
liquibase_scripts
...
schema.json
main
java
...
test
resources
liquibase_scripts
...
schema.json
So than I build my project, folder db with liquibase scripts added to distributive.
In unit tests I use H2 database and want to load schema from db/liquibase. I create bean
#Bean
public SpringLiquibase springLiquibase() {
SpringLiquibase springLiquibase = new SpringLiquibase();
springLiquibase.setDataSource(dataSource());
springLiquibase.setChangeLog("classpath:/liquibase/sam.json");
return springLiquibase;
}
The problem is that method setChangeLog look at resource folder in test folder.
So to solve the problem I copied all liquibase scripts to the test/resources directory.
But this is not ok becouse now I have 2 copies of scripts in different folders.
Is there a way to force springLiquibase.setChangeLog find scripts in any folder not only in test/resources?
In Maven build configuration you can define testResources, which may be directories and files. It looks like this:
<build>
<testResources>
<testResource>
<directory>${project.basedir}/db/liquibase_scripts</directory>
</testResource>
</testResources>
</build>
With such configuration Maven copies the files into the target/test-classes directory. Thanks to that those files can be used as test resources in the code, but there's no duplication in the project files.
Im using such configuration (Liquibase + testResources) in one of my projects. To better reproduce your problem, I've created a separate branch, where you can find the configuration described above - see: this commit diff. All test pass after the change.
I have a LibGDX project with some tests. The structure is as follow:
core/src -> for my java sources code
core/test -> for my tests source code
core/assets -> for all my assets
When I run the tests from eclipse, they all go green but whenever I try to run them from the gradle command line (./gradlew test) I get an error with the assets folder. I believe this is because the tests are not launched from the assets folder as it is from eclipse.
How can I solve this problem ? Is there a way to tell gradle to use core/assets as the workspace directory when running the tests ?
Here is the error I get:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: myasset.png
I found a way to achieve what I wanted. I post my solution here for anyone that might need it. There is a property named workingDir for the test task in gradle. So I just needed to set it to the right folder. Inside the build.gradle file of your project (the root folder) just add the following section:
project(":core") {
apply plugin: "java"
// Add the following test section
test{
workingDir= new File("/assets")
}
// Rest of the file
}
That's it! My tests are running green from the command line now.
Processing's (processing.org) basic library jars are not on clojars or maven. I have a project going with clojure and would like to upload the jars to clojars under my username. It was kind of tedious to get them into my .m2 folder one a time. I will be need to be able to access them via clojars so that others can help me with my project. How can I upload these dependencies?
lein deploy clojars doesn't upload the dependencies - all the processing library jars.
My processing localrepo is also on github stored here:
https://github.com/originalsurfmex/originalsurfmex_m2/tree/master/repository/processing
If this info http://blog.rueedlinger.ch/2012/09/use-github-as-maven-remote-repository/ is useful for you to use a github repo as maven repository, then you only have to declare this github repo on your project.clj.
You can see an example here https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L76
:repositories [["your-id" "https://github.com/originalsurfmex/originalsurfmex_m2/tree/master/repository"]]
UPDATE:
You are right, the comment above doesn't fully answer your question, so I'll try again :)
So, how to push a lib to clojars if the dependencies aren't in clojars yet?
I never pushed a lib to clojars so the next are only ideas but, I've been searching the same problem in one real published case (quil/quil) and these are my conclusions:
In the quil project.clj the "problematic" dependencies are in "handmade" clojars. if you look into your ~/.m2 local repository you can find all of them prefixed by "org/clojars/" instead of "org.processing",
The dev [#samaaron] that pushed these dependencies to clojars had to create one separated project by dependency, configured it:
<dependency>
<groupId>org.clojars.processing-core</groupId>
<artifactId>org.processing.opengl</artifactId>
<version>1.5.1</version>
</dependency>
and pushed each one to clojars.
I think that if you take a look inside one of these quil dependencies on your local maven repo you'll figure aout the way you have to follow to that (basically: to have a java project, download the source, configure pom.xml and upload java code to clojars )
Good luck
If you're still using Processing 1.5.1, you can find all the required jars on Clojars, however in that case you could also just pull Quil into your project, which then pulls in all other repackaged Processing jars too (incl. native libs for OpenGL).
Here're some more general bullet points for repacking a jar & uploading it to Clojars: https://groups.google.com/forum/#!topic/clojure/KxwhVg7L_gA
Thanks for your help and links so far. This is as far as I have gotten:
I have had some success - minus the ability to sign jars and poms.
I gotta admit though its kind of a pain. Here is the process. There must be an automated way to do this right?
Go to your .m2/repository/group/library/version/ folder
md5sum lib.jar > lib.jar.md5
sha1sum lib.jar > lib.jar.sha1
Change the groupId in lib.pom from
<groupId>libgroup</groupId>
to
<groupId>org.clojars.username.libgroup</groupId>
Add missing sections in lib.pom by hand otherwise clojars complains:
<description>processing-libs</description>
<url>http://www.processing.org</url>
<scm>
<tag>something relevant?</tag>
<url>somewhere relevant?</url>
</scm>
<licenses>
<license>
<name/>
<url/>
<distribution/>
</license>
</licenses>
<developers>
<developer>
<id/>
<name/>
<email/>
</developer>
</developers>
<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo/</url>
</repository>
</repositories>
md5sum lib.pom > lib.pom.md5
sha1sum lib.pom > lib.pom.sha1
scp lib* clojars#clojars.org:
Here they are in github (the md5 and sha1 files not included of course):
https://github.com/originalsurfmex/originalsurfmex_m2/tree/master/repository/processing/core/2.1
https://github.com/originalsurfmex/originalsurfmex_m2/tree/master/repository/processing/gluegen-rt/2.1
Here they are in clojars:
https://clojars.org/org.clojars.originalsurfmex.processing/core
https://clojars.org/org.clojars.originalsurfmex.processing/gluegen-rt
Before I go ahead and add all of these libs I have two concerns:
I have polluted clojars.org my mistakes --> https://clojars.org/users/originalsurfmex
Is it gonna be a waste or a deal breaker that my jars and poms aren't signed? I can't seem to figure out how to sign them. I have SSH and PGP setup on clojar.org and scp runs just fine.
I have a VS2010 unit test project set to using SpecFlow 1.8.1 and mstest. In order to get the SpecFlow unit tests working, I've done the following:-
I added the references to the following files in my project:-
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
TechTalk.SpecFlow.dll
Note that the TechTalk.SpecFlow.dll has been added into my project and the reference points to that file.
I've set the "Copy Local" property of the TechTalk.SpecFlow.dll reference to True.
I've also added an App.Config that specifies "MsTest.2010" as the provider, and regenerated all code-behinds for the SpecFlow features.
Everything works in my VS2010, the tests run successfully in both the SpecFlow testrunner and the mstest test runner. BUT when I try to run the mstests in TFS 2008 (using a .vsmdi test list file), it failed with the following exception:-
Class Initialization method MyNamespace.MyTestFeature.FeatureSetup threw exception.
System.Configuration.ConfigurationErrorsException:
System.Configuration.ConfigurationErrorsException: An error occurred creating the
configuration section handler for specFlow: Could not load file or assembly
'TechTalk.SpecFlow' or one of its dependencies. The system cannot find the file
specified. (D:\Projects\TestProject\TestResults\administrator_MYPC 2012-06-27
18_30_05_Any CPU_Debug\Out\TestProject.DLL.config line 4) --->
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow'
or one of its dependencies. The system cannot find the file specified.
Note that the TFS built the project fine and it runs other unit tests in the same project (normal mstests, not SpecFlow) without problems. It only failed for the SpecFlow test runs.
So what am I doing wrong?
Edit: The contents of my App.Config file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="specFlow"
type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<unitTestProvider name="MsTest.2010" />
<runtime detectAmbiguousMatches="true"
stopAtFirstError="false"
missingOrPendingStepsOutcome="Inconclusive" />
<trace traceSuccessfulSteps="true"
traceTimings="false"
minTracedDuration="0:0:0.1" />
</specFlow>
</configuration>
Following the instruction on this site and this site:
the command Tools > Library Package Manager > Package Manager Console allows you to type in PM> Install-Package SpecFlow
when the prompts returns "installed successfully", the SpecFlow Assembly now appears in the references of your project. And the MSTest project now compiles succesfully (at least for me).
I got this error as well, in my case the problem was that I was using the \...\obj\Debug||Release\ folder as target and not the \...\bin\Debug||Release\ folder. Looking in these folders I saw that the TechTalk.dll assembly was missing from the former. Simply switching in my .bat file the problem was fixed.
Sometimes VS2013 is looking for SpecRun dlls not in project folder, but in C:\Users\**YOUR_USER**\AppData\Local\Temp\VisualStudioTestExplorerExtensions\SpecRun.Runner.1.3.0\tools. So you just need to put all necessary SpecFlow libraries therel
One hack I found to get it working is to add another class for EVERY single SpecFlow feature that I created in the project. The class looks like this:-
[DeploymentItem(#"TechTalk.SpecFlow.dll")]
partial class MyTestFeature { }
// The above class-name needs to come from the auto-generated code behind
// (.feature.cs) for each SpecFlow feature.
I consider this as a very nasty hack, but it does provide a clue as to why it didn't work. It would be good if anyone comes up with a more elegant solution.
I finally found the more proper fix for this issue. I just need to add a post-build event to remove the .config file from the build output. (The App.config file is used only to generate the code-behind during design time. It is not used at all during runtime, so it can be removed.)
The command for the post-build event looks like this:-
del /f /q "$(TargetDir)$(TargetFileName).config"
Correction: The .config file is used for generating inconclusive results, so a better post-build event command is as follows:-
if "$(IsDesktopBuild)"=="false" del /f /q "$(TargetDir)$(TargetFileName).config"
I used to work with Hudson on my project, and lately I had to move it to a new server.
I configured it the exact same way it use to be (for all I can tell) but when I try to launch a build, it fails and I get the following error:
Démarré par l'utilisateur anonymous
Checking out http://[...]/trunk/MyProject/ear
A .classpath
A .project
A target
AU target/ear-1.0-SNAPSHOT.ear
A target/application.xml
A target/ear-1.0-SNAPSHOT
A target/ear-1.0-SNAPSHOT/META-INF
A target/ear-1.0-SNAPSHOT/META-INF/application.xml
AU target/ear-1.0-SNAPSHOT/web-1.0-SNAPSHOT.war
AU target/ear-1.0-SNAPSHOT/business-1.0-SNAPSHOT.jar
A pom.xml
A .settings
A .settings/org.eclipse.jdt.core.prefs
A .settings/org.maven.ide.eclipse.prefs
At revision 136
no change for http://[...]/trunk/MyProject/ear since the previous build
Found mavenVersion 3.0.2 from file jar:file:/usr/share/maven/apache-maven-3.0.2/lib/maven-core-3.0.2.jar!/META-INF/maven/org.apache.maven/maven-core/pom.properties
Parsing POMs
ERROR: Echec à la lecture des POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact com.rha:MyProject:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 9, column 10
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:325)
at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:360)
at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:330)
at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1148)
at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:991)
at hudson.FilePath.act(FilePath.java:756)
at hudson.FilePath.act(FilePath.java:738)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.parsePoms(MavenModuleSetBuild.java:698)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.doRun(MavenModuleSetBuild.java:531)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:420)
at hudson.model.Run.run(Run.java:1362)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:405)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:145)
Finished: FAILURE
The pom.xml file when I got to Hudson "workspace" looks like this:
[...]
<parent>
<groupId>com.rha</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
[...]
<dependencies>
<dependency>
<groupId>com.rha</groupId>
<artifactId>business</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.rha</groupId>
<artifactId>web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
[Edit]
Actually I forgot some important informations:
My project is divided into 3 parts:
business (packaged into .jar)
web (packaged into a .war)
ear (packaged the .war and .jar into a .ear)
I'm using Subversion, and under my "trunk" folder I got a "MyProject" folder including:
.project
.settings/
business/
ear/
pom.xml
src/
web/
what happens is:
in my Hudson job configuration, I filled the SVN field "repository URL" with:
http://[...]/trunk/MyProject/ear
and here is the "pom.xml" from "MyProject" folder:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
[...]
<modules>
<module>business</module>
<module>web</module>
<module>ear</module>
</modules>
[...]
so the parent "pom.xml" is actually located at "../pom.xml" on my SVN repository, under "trunk/MyFolder".
But Hudson can't see it for some reason (but like I said, it used to work on the previous server).
Any clue ?
[/Edit]
I guess this is a rookie mistake, I'm a total beginner on Maven, but I just can't figure out why it's not working anymore ...
Any help will be greatly appreciated !
Nicolas
relativePath (of the parent) defaults to ../pom.xml. It looks like it is not present in there. You could set it to an empty value so that maven downloads it as a dependency.
<relativePath/>
This link discusses this.
[Edit: based on the edits to the question]
Hudson only sees the source code inside ear folder. Though the parent pom is present in SVN, it is not available to Hudson. Missing parent pom was aa warning in Maven 2 but strict in Maven 3.
There are two ways to solve this.
One is to specify to hudson, the url http://[...]/trunk/MyProject/. You can then chose to build all the modules or still choose to build the pom.xml of ear project alone.
The other is to manually run mvn install on the hudson system so that the parent pom gets deployed once and thereafter used by hudson. However, this will not get updated if parent pom is subsequently changed.
Retrieving the Root-POM from the Maven-REPO should usually also work (like you do), but I would expect you havn't triggered the root pom to be installed into the REPO on the new hudson site so far.
To avoid this use the relativePath property, e.g. something like this:
<relativePath>../pom.xml</relativePath>
in your <parent> tag which will tell maven to look for the root pom in your module structure.
I had the same problem with Hudson, Sonar plugin and a multi-module Maven project: "Non-resolvable parent POM" when Hudson tried to run sonar:sonar. The solution was to specify the Root POM location in the Hudson job configuration under the Sonar section.
The project structure in SVN (each one is a Maven project with pom.xml in the project root):
foo-parent
+- foo-ui-module
+- bar-other-module
I have individual Hudson jobs for each project, "foo-parent", "foo-ui-module" and "bar-other-module". The Sonar run in a Hudson job could not find the parent POM even though the build was successful until that point. Maybe the Sonar plugin doesn't use the same Maven settings as the rest of the job because it didn't try to look for the parent POM from our Artifactory repository, not even with <relativePath/> in the project POM.
The place for the Root POM setting was under the job's Configure -> Sonar -> Advanced -> Root POM: ../foo-parent/pom.xml (I have foo-parent job at this path)
We managed to get this working by simply deleting the relevant pom file, plus some sort of metadata file with a similar name in the same folder, from the .m2/repository/a/b/c folder on our jenkins server.
Rerunning the jenkins build after doing this worked just fine.
Hope this helps someone...