Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Friday, December 14, 2012

Tilded Target Folder

I think I finally grokked the following unexpected interaction between svn and Maven/Eclipse Workspace Resolution feature. First, a bash illustration:

bash-3.2$ svn stat
?       .classpath
?       .project
?       .settings
~       target

See the "~       target"? That is what I believe was the cause of a mysterious build problem. (The tilde is probably due to me changing from "svn:ignore *" inside target dir, to "svn:ignore target", after discovering that the former doesn't work well. Maybe more in other blog post.)

The symptom of the problem I've been having for a few hours can be demonstrated and summarized like this: 

No problem building in maven. 

Lots of errors in red in Eclipse, as if a Maven dependency is not resolved somehow. 

Turning off Workspace Resolution makes the errors go away. 

Conclusion: something is up with Workspace Resolution. 

Theory: 1) there is something wrong with the target directory; 2) workspace resolution uses a project's target directory for dependencies (perhaps just points to $dependee_project/target/classes on the classpath). 

But that seems crazy. Surely the build should care how SVN flags the target directory? But the coincidence is a bit too strong to ignore. 

--

Turns out that Eclipse clean + build fixed it. Don't know why.

But the target folder had a severe SVN weirdness...


Doing "svn update target" failed bizarrely: "svn: Unable to lock 'src'". Huh?

Finally it got unstuck, inside Eclipse: 

    E   .../target
    Updated to revision 23696.
    ===== File Statistics: =====
    Existing: 1



I've never seen this 'E', existing, before. I must've managed to set a svn:ignore on it, but it existed in the repo. Or something.


E-Maven Update Project Configuration Problem

Eclipse/Maven "Update Project Configuration" problem: "can't update ... because '.project' is not in sync with file system." The "not in sync with file system" usually means that Refresh helps, but not so in this case. Turns out that Eclipse somehow thought I had unsaved changes; saved, and that seems to have solved the problem for Eclipse.

Maven Idea

Here's a radical idea to simplify the usage of Maven, especially when considering Eclipse cooperation.

How about not using test scope, but instead create a 'project-test' for every 'project'? Some advantages:

The pom.xml files will be cleaner.

The single-classpath Eclipse will not be a problem any more.

One will not have to think about the interaction between the declared dependency scope and the importing dependency scope. (Unfortunately, the 'provided' scope is still needed, but that is pretty simple.)

If one would want to import test code into another project, no need to fiddle with '-tests' attachment.

One can build with-out tests, which is quicker, and could likely allow tests to be run quicker, ironically, because of parallel execution. Or you could collect all tests before running them.

The odd thing is that maven wasn't designed this way from the start. It would have dispensed with a lot of extra complexity. Etcetera.

Thursday, December 13, 2012

Maven Source Properties That Don't Work


When I do 'Maven > Update Project Configuration' in Eclipse, this seems not to work: 

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.build.source>1.6</project.build.source>
        <project.build.target>1.6</project.build.target>
    </properties>
    
But this seems to work: 

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
     ...
    
Too bad, since the first xml is neater. 

---

PS. One sign that there is some mix-up with 1.5/1.6, is that the @Override annotation acts up.

Tuesday, December 4, 2012

Maven Is Back, Stronger Than Ever

Guess what this does, in proper maven resource plugin context:

<configuration>
<outputDirectory>target/classes</outputDirectory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.class</exclude>
<exclude>**/.svn</exclude>
</excludes>
<resources>
<resource>
<directory>src/test/java</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>

Copies resources out of src/test/java and src/main/java, excluding files matching the specified patterns? 

Wrong. Or, mostly wrong. 

The exclusions will apply to the src/test/java directory paths, but not the src/main/java. Yep, at least in the version we use. 

Caveat utilitor.


Monday, December 3, 2012

Maven Copy Plugin

This (new?) Maven 'copy' plugin: http://evgeny-goldin.com/wiki/Copy-maven-plugin, seems to be a useful tool to simplify some Maven projects. It seems to be a good way to using a minimal number of plugins for common tasks. This is not a deep review; I'm just blogging this as sort of a mental note.

But it could be used for the following problem: I recently learned a second way that the 'real' Maven and running under the Eclipse Maven plugin differs, in that resource files in /src/man/java are copied; but not so with Maven defaults. (The other difference I know of is that Eclipse has only one classpath, the same for both src/test and src/main. Fertile ground for bad imports.) It's easy to add with a standard plugin, but if you have many such small tasks, then possibly this 'copy' plugin will be better than a bunch of disparate plugins. Maven is verbose enough, I think.

Wednesday, November 21, 2012

Learning to Deploy (Maven)

I am in the process of learning how to do public deploys with maven; for instance, to publish java library artifacts. Uploading to AWS S3 would be nice, but one step at a time.

I found no 'deploy' menu item in Eclipse's Maven menus. So I made a nice little script:
cd $(dirname $0)
ls -l

echo -----------------------------------
echo deploying...
echo -----------------------------------

mvn javadoc:jar deploy

echo -----------------------------------
echo deploy script done.
echo -----------------------------------
echo 

echo -----------------------------------
echo damage report...
echo -----------------------------------

find /tmp/maven-tmp-repo

echo -----------------------------------
echo now back to your regular shell, see you later. 
echo -----------------------------------

$SHELL
I have found it to be a nice pedagogical tool. It's of course not much different from doing it manually but it saves work. I've put it in a 'mvn-deploy.command' file next to the 'pom.xml', which also makes for quick deploys -- it's just a double-click to start from inside Eclipse (provided you set the 'executable' property/flag under Properties); no having to navigate to the right directory in the terminal.

(Btw, why doesn't Eclipse have a 'Open Folder In Shell/Terminal'. Or maybe it does, somewhere. Do tell!)

The 'ls -l' at the start is just for context. The 'find' at the end lists all files in the makeshift repository. Yeah, almost forgot: you need something like this in your pom.xml:
<distributionManagement>
    <repository>
            <id>local-tmp-repo</id>
            <name>Temp Folder</name>
            <url>file:///tmp/maven-tmp-repo</url>
        </repository>
</distributionManagement>
Pardon the formatting. (EDIT: Shit, now it looks even worse: '& gt;' and all. Damn you, blogger editor. -- No wait, it looks ok in 'print'.)

So, you can now see in your terminal, or by inspecting the /tmp/ file system tree, how maven adds files like '/1.0-SNAPSHOT/maven-metadata.xml', 'pub-lib-1.0-20121121.203440-1.jar', 'pub-lib-1.0-20121121.205813-2-javadoc.jar', etcetera, without digging in to .m2 (these files are probably simply copies out of the .m2 local repo).

That's it, readers. I just might return with a post about the maven shapshot process, in very concrete terms.

Artifactory Online: Reviewlet

Reviewlet of Artifactory Online.

Home Url: https://secure.artifactoryonline.com/

Sign-Up: easy, but a bit too much filling in of forms. And either there's a glitch, or I mistyped something: the first confirmation mail didn't get back, so I had to add a '2' to the chosen domain, as it was reported as taken. Oh well.

Clicking confirmation link brought me in to the setup process, very simple, a bit slow; but from an implementor viewpoint I can see that it may be hard to keep a pool of fired-up instances ready.

I managed to snap these screenshot during the automatic process:



Done.

Next comes the finding-your-way. I dabbled with Nexus and Artifactory a few years back, so I recognize some of the repo naming schemes. But even thinking a bit, I must confess that I don't remember really fully understanding the scheme.

I am looking to have two 'permissions' of repos, one publicly available, and one for internal libraries. Well, actually, only the public one is really needed. So how do you do such a thing? Not immediately obvious if it is part of the factory set-up or not.

----

Ok, so an unexpected item in the review: finding-your-way-back-to-the-app. Can't seem to find a link from the main page. So I guess browser history, or find the confirmation email in the email history.

----

The repository search browser is pretty nice; I like to have this comprehensive data available like this:


Here, to the left (in this partial screenshot) you can see the list of repos. None of these seem to be the one I am looking for: publicly released artifacts. All these repo names end in '-local'. I suppose the name I am looking for would along the lines of 'libs-releases-public' (and perhaps 'libs-snapshots-public'). Isn't that a common enough usage that the default setup might want to include one?

----

The search I can only presume that it works, since all the shown repos seem to be empty. Maybe the repo1-cache contains something to search for...no. Even such a general pattern as "*X*" finds nothing. I can't get a clue as to why. Possibly they are all empty. One has to click the 'Show...' link as seen in the screenshot to get that number, unfortunately. In each selected one -- not very generous.

----

[TBD-M]

Monday, November 12, 2012

Fix Maven Source Version Having No Effect

In a recent article at http://impossible-is-development.blogspot.com/2012/11/basic-maven-project-build-fix-tip.html, I wrote about a trick to get the .classpath file to reflect the src/main/java etcetera build structure. This trick actually helps in another not-to-uncommon situation: unsyncronized source versions.

If you create a new pom.xml, it may happen that there is no Java versions information given. The version can be given in two ways; via some xml using a 'properties' tag, or via more xml. 

Plugin config: 
<build>
<plugins>
<plugin>
maven-compiler-plugin
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin></plugins>
Sorry about the formatting. (Doesn't the Blogger editor suck something awful for quotes and code? ...hmm...can one blog on Github?)

<project.build.source>1.6</project.build.source> <project.build.target>1.6</project.build.target>
(Again, sorry about the formatting.)

Now; if you add this to an existing pom.xml, Eclipse may fail to take note of this change automatically. Maybe it never takes note. In any case, the same solution applies here as in the earlier blog post: just disable and enable dependency management.

Tuesday, November 6, 2012

Java Project Modularity Woes

We want to publish:
1) an API (DTOs and stuff), 20 classes or so.
2) a devkit. A simple server based on Jetty, less than ten classes.

Now, of course there are ways to do it. But no really good ways, I believe.

We may have to use Maven here.


Basic Maven Project Build Fix Tip

Sometimes, in Eclipse, a maven project will not be properly set up. For instance, when you create a maven project by creating a pom.xml file inside a folder. This can be seen by inspecting the '.classpath' file -- it will contain only these three items (or similar):


<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> 

<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> 

<classpathentry kind="output" path="target/classes"/>


Then, what you do is this: simply "Disable Dependency Management" and then "Enable Dependency Management" from the "Maven" menu in the contextual menu from the project. If you keep the ".classpath" file open, you'll be able to see the what happens.

In the 'Disable' step, the Maven entry disappears:
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
Then, in the 'Enable' step, the entries which enable the build appears:
kind="src" output="target/classes" path="src/main/java"> 
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
 along with the 'MAVEN2_CLASSPATH_CONTAINER' thing mentioned above. Done!

--

Today I discovered that the above maneuver is in fact useful to handle another problem involving mis-synchronization between ".classpath" and the "pom.xml" file. Article forthcoming.

Thursday, October 25, 2012

Maven Dependency Type 'jar' Not Added Automatically

After a half-hour or so of not understanding why some Java imports didn't work.

I noticed that the letters 'jar' was missing from the dependency listing.

I had tried using the Eclipse maven assist GUI to add a dependency.

And apparently the it's not enough to just search for the dependency and say OK when selected.

Which is Odd because I've done it a few times and it's worked fine.

All these little things.

All. These. Little. Things.

That.

Add.

Up.

To.

A.

Large Amount Of Wasted Life And Time And Money.

Friday, September 7, 2012

Juno II, The Brightening Up

Back in Eclipse Juno, incidentally, had to use a new Eclipse due to a mysterious error with a cryptography module not getting found. Stopped using it a couple months ago because it seemed to have small bugs. Possibly one of them was that Subclipse seemed badly integrated. The small file status symbols didn't show; or sometimes all files appeared with the question mark symbol making me think it didn't work.

But today it is looking fine, after both things happening at first; no symbols, then question marks. Then after a restart and a "Could not write metadata for '/RemoteSystemsTempFiles' modal dialog, and a while, and now they are showing. It might be the synchronization command I invoked was needed to finally get them showing.

So if you're seeing the same thing, just be a bit patient, do a 'Synchronize', and your day may brighten up some.


---

Oh, no, not bright. Installed the 'm2e' Maven Plugin (I think). Going from not finding "javax.persistence", to:


 The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

And 'java.lang.Object' would probably be the most resolvable class in Java. 

---

Had to explicitly convert the project to a maven project. Odd, because: 
1) the .project had a couple of maven-related settings; maven2Nature and whatnot. 
2) ISTR that .pom files are auto-detected? I probably remember wrong. 

Better. 

...except: 

maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution: default, phase: initialize)
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution: create_db_and_user, phase: initialize)
Plugin execution not covered by lifecycle configuration:
 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (execution:
 create_test_db_and_user, phase: initialize)

Great. Well,  I believe we had at least the copy-dependencies those to support an old ant project setup, copying maven lib dependencies into some folder for ant to deal with, so that might be ok.

...maybe I should have installed m2eclipse instead? I thought they were practically the same thing. But 
here is an article that begs to differ: http://java.dzone.com/articles/migrating-m2eclipse-m2e. 

Ok, so how do I uninstall m2e and change to m2eclipse? The menus give no clue. 

...ah got it: select "Install Software..." menu item; the install dialog contains a "already installed" link. It has "Uninstall..." buttons. Of course, why didn't I think of that first? 

Selected the two items that seemed to have to do with m2e. (Restart, problems saving state modal dialog...)

---

Ok, Eclipse Marketplace, what have you got for me? m2eclipse-wtp seems to be the closest match for m2eclipse. ...ouch, "unsigned content". 

Let's try the other one, "Install New Software...". m2eclipse-wtp -- what the, it contains only m2e? Maybe I can't get an older m2eclipse with Juno? 

-- 

The blog I found above has a nice article here: 
which seems kind of relevant; for instance this passage: 
However, the problem is much more widespread than m2eclipse. It’s very similar to issues adressed in Andrew Spencer’s post, only more so since if we don’t upgrade, we may have to keep an Eclipse instance for each project, that has to be shared between all team members. Right now, I don’t have any solutions for this problem, apart from changing the code to keep in synch with the tool.
---

Tried the "Discover new m2e connectors" link in quick tip. I don't know what those are, because nothing showed up.