You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Lucio Crusca <lu...@sulweb.org> on 2012/10/15 13:51:26 UTC

modules, dependencies, whatelse?

Hello *,

I'm new to maven. I'd like to mavenize three projects of mine. Let's say they 
are myLib1, myLib2 and myLib3. My directory structure is

~/mavenprojects/myLib1
~/mavenprojects/myLib2
~/mavenprojects/myLib3

myLib3 depends on myLib1 and myLib2; myLib2 depends only on myLib1. The three 
libraries are in development stage, so I change their code very often. I need 
a maven setup that, when compiling myLib3, automatically compiles myLib1 and 
myLib2 also, if their source code has been changed, and recreates respective 
jars. The same goes for myLib2 in respect to its myLib1 dependency.

I've tried adding myLib1 as a module of myLib2 in myLib2 pom file, but then I 
had to change the packaging to "pom", which stopped maven from compiling and 
packaging myLib2.

Then I considered adding the compiled jars as dependencies, but in this case I 
don't have a maven repository to query, and I don't want to manually install 
myLib1 and myLib2 jars, since that would keep maven from recompiling the 
respective sources.

What's the correct solution in my case?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by John Patrick <nh...@gmail.com>.
Step By Step will get you though this, once you understand Maven more
it will become a lot clearer. Nexus is a good idea and i should
probably do that myself but it's probably step 2 after getting this
working.

1) Create pom for myLib1, packaging type jar
2) myPom/myLib1$ mvn clean install
3) Create pom for myLib2 and add dependency for myLib1, packaging type jar
4) myPom/myLib2$ mvn clean install
5) Create pom for myLib3 and add dependency for myLib1, packaging type jar
6) myPom/myLib3$ mvn clean install
7) Create pom for myPom in parent directory of myLib1, myLib2 and
myLib3, packaging type pom
8) Add <modules><module>myLib1</module><module>myLib2</module><module>myLib3</module></modules>
into the myPom pom
9) myPom$ mvn clean install
10) Based upon the groupId you have used, delete it manually from your
own maven repository e.g. ~/.m2/repository/x/y/z
11) Manually delete myLib1/target myLib2/target myLib3/target
12) myPom$ mvn clean install

Steps 10 and 11 remove your locally built version and followed by step
12 proves that all the dependencies work correctly and dependencies
your in control of all build in the right order and installed into
your local repository.

After that look into SNAPSHOTS and Nexus, once your project is building.

Hope this helps,
John

On 15 October 2012 20:04, Ron Wheeler <rw...@artifact-software.com> wrote:
> On 15/10/2012 12:36 PM, Lucio Crusca wrote:
>>
>> In data lunedì 15 ottobre 2012 16:16:44, Ron Wheeler ha scritto:
>>
>>> Set up a Maven repo like Nexus. This is worth the small effort for the
>>> improvement in your life with Maven.
>>
>> I feared this reply and badly hoped not receiving it...
>>
>>> Even if you are a 1 man shop, it is worthwhile.
>>
>> This is reassuring (I actually am a 1 man shop).
>>
>>> Set it up on your workstation if you have to or put it on a small server
>>> in the cloud.
>>
>> I'm often on the move and I often work with slow internet connections, I
>> suppose my notebook is the best choice. Have you got any pointers to
>> howtos
>> for this?
>
> If you are using Nexus, I would just follow the installation instructions.
>
> Read the Nexus instructions carefully.
> The setup is a bit out of the ordinary so be careful about making
> assumptions about how "normal" webapps work.
> If you run into trouble, the Nexus forum is very active and a lot of the
> really bright lights of Maven are also involved in Nexus support so you
> should get very consistent advice between the 2 forums.
> Please post questions in the right forum.
> Maven supports at least 3 different repositories and there is sensitivity on
> the part of some people about the Maven forum leaning towards one repository
> package or another.
>
> I am not involved in either project or any repo project so I tend to be a
> bit more outspoken in my praise of Nexus but I am not an expert in
> repositories and have no experience with the other repos. From the traffic
> here, I gather that the other solutions are also very good.
>
> The one thing that having a repo will do for you is to make you much more
> aware of proper release practices and to a certain extent force you into
> using SNAPSHOTs correctly.
> We ran for 2 years without a repo and I feel that we lost a lot of time
> because of that. It took us a lot longer to understand Maven's best
> practices and the "Maven way" without the repo.
>
> You should also take a quick look at the Maven project team
> http://maven.apache.org/plugins/maven-project-info-reports-plugin/team-list.html
> so that you recognize the people who are giving you advice.
>
> Key thing to keep in mind. "Unless you are building something really, really
> out of the ordinary, bordering on bizarre, thousands of people have already
> built something similar to your project and there is a simple Maven Best
> Practice already available."
>
> Ron
>
>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
>
> --
> Ron Wheeler
> President
> Artifact Software Inc
> email: rwheeler@artifact-software.com
> skype: ronaldmwheeler
> phone: 866-970-2435, ext 102
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 15/10/2012 12:36 PM, Lucio Crusca wrote:
> In data lunedì 15 ottobre 2012 16:16:44, Ron Wheeler ha scritto:
>
>> Set up a Maven repo like Nexus. This is worth the small effort for the
>> improvement in your life with Maven.
> I feared this reply and badly hoped not receiving it...
>
>> Even if you are a 1 man shop, it is worthwhile.
> This is reassuring (I actually am a 1 man shop).
>
>> Set it up on your workstation if you have to or put it on a small server
>> in the cloud.
> I'm often on the move and I often work with slow internet connections, I
> suppose my notebook is the best choice. Have you got any pointers to howtos
> for this?
If you are using Nexus, I would just follow the installation instructions.

Read the Nexus instructions carefully.
The setup is a bit out of the ordinary so be careful about making 
assumptions about how "normal" webapps work.
If you run into trouble, the Nexus forum is very active and a lot of the 
really bright lights of Maven are also involved in Nexus support so you 
should get very consistent advice between the 2 forums.
Please post questions in the right forum.
Maven supports at least 3 different repositories and there is 
sensitivity on the part of some people about the Maven forum leaning 
towards one repository package or another.

I am not involved in either project or any repo project so I tend to be 
a bit more outspoken in my praise of Nexus but I am not an expert in 
repositories and have no experience with the other repos. From the 
traffic here, I gather that the other solutions are also very good.

The one thing that having a repo will do for you is to make you much 
more aware of proper release practices and to a certain extent force you 
into using SNAPSHOTs correctly.
We ran for 2 years without a repo and I feel that we lost a lot of time 
because of that. It took us a lot longer to understand Maven's best 
practices and the "Maven way" without the repo.

You should also take a quick look at the Maven project team 
http://maven.apache.org/plugins/maven-project-info-reports-plugin/team-list.html 
so that you recognize the people who are giving you advice.

Key thing to keep in mind. "Unless you are building something really, 
really out of the ordinary, bordering on bizarre, thousands of people 
have already built something similar to your project and there is a 
simple Maven Best Practice already available."

Ron

>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by Lucio Crusca <lu...@sulweb.org>.
In data lunedì 15 ottobre 2012 16:16:44, Ron Wheeler ha scritto:

> Set up a Maven repo like Nexus. This is worth the small effort for the
> improvement in your life with Maven.

I feared this reply and badly hoped not receiving it...

> Even if you are a 1 man shop, it is worthwhile.

This is reassuring (I actually am a 1 man shop).

> Set it up on your workstation if you have to or put it on a small server
> in the cloud.

I'm often on the move and I often work with slow internet connections, I 
suppose my notebook is the best choice. Have you got any pointers to howtos  
for this?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by Ron Wheeler <rw...@artifact-software.com>.
I agree with John's suggestion.
You also need to read up on SNAPSHOTs.
Check out the free books at http://maven.apache.org/articles.html and 
look for best practices.

Set up a Maven repo like Nexus. This is worth the small effort for the 
improvement in your life with Maven.

Even if you are a 1 man shop, it is worthwhile.
Set it up on your workstation if you have to or put it on a small server 
in the cloud.

Ron


On 15/10/2012 8:20 AM, John Patrick wrote:
> If this was me I would create a new pom, which would be the parent for
> the 3 libraries, I would then also build at that level.
>
> e.g.
> ~/mavenprojects/pom.xml (packaging pom)
> ~/mavenprojects/myLib1/pom.xml (packaging jar)
> ~/mavenprojects/myLib2/pom.xml (packaging jar)
> ~/mavenprojects/myLib3/pom.xml (packaging jar)
>
> Basically that is how every project I've worked on works. You have to
> define the parent and relative Path correctly in the lib projects, and
> add modules into the parent pom. Basically one pom per thing,
> sometimes over kill but often easier then scaling projects up or
> moving between projects.
>
> We have ~65 pom on my main project, ~15 are pom's to logically group
> functionaility, some are simply a single wsdl or xsd, others are the
> jpa layer.
>
> Others might have different views but that is how I'd do it.
>
> On 15 October 2012 12:51, Lucio Crusca <lu...@sulweb.org> wrote:
>> Hello *,
>>
>> I'm new to maven. I'd like to mavenize three projects of mine. Let's say they
>> are myLib1, myLib2 and myLib3. My directory structure is
>>
>> ~/mavenprojects/myLib1
>> ~/mavenprojects/myLib2
>> ~/mavenprojects/myLib3
>>
>> myLib3 depends on myLib1 and myLib2; myLib2 depends only on myLib1. The three
>> libraries are in development stage, so I change their code very often. I need
>> a maven setup that, when compiling myLib3, automatically compiles myLib1 and
>> myLib2 also, if their source code has been changed, and recreates respective
>> jars. The same goes for myLib2 in respect to its myLib1 dependency.
>>
>> I've tried adding myLib1 as a module of myLib2 in myLib2 pom file, but then I
>> had to change the packaging to "pom", which stopped maven from compiling and
>> packaging myLib2.
>>
>> Then I considered adding the compiled jars as dependencies, but in this case I
>> don't have a maven repository to query, and I don't want to manually install
>> myLib1 and myLib2 jars, since that would keep maven from recompiling the
>> respective sources.
>>
>> What's the correct solution in my case?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by Barrie Treloar <ba...@gmail.com>.
On Tue, Oct 16, 2012 at 3:19 AM, Wayne Fay <wa...@gmail.com> wrote:
>> The problem with this is that I also need to build standalone jars of myLib2
>> and myLib3, and they need myLib1 themselves. Their code refers to classes in
>> myLib1 and myLib3 code defers also to classes in myLib2. myLib2 and myLib3 do
>> not even compile if they don't have myLib1/myLib2 listed as dependency in
>> their pom file. But if I list them as dependecies, those are expected to be
>> found in a repository or manually installed. Otherwise if I list them as
>> modules, I'm forced to packaging="pom", so no standalone jars...
>
> Just set things up as you've been told and build your projects from
> the top/parent each time, not from the children. Then the reactor
> finds the files it needs when it builds each library. Use packaging of
> "jar" in each lib, and use packaging "pom" for the top parent.

You dont need Nexus yet for your 3 module setup.

I assume the number of classes you have are tiny* (by some definition of tiny).
If you whole build run from the top level, as Wayne suggests, take
longer than 5 minutes then we can help you to speed it up.

Since you are new its easier to start with the small steps.

When you are feeling braver you can run with options like "--also-make".
But in your case I doubt that this will save you any cpu cycles.

Most people work in an IDE rather than on the command line.
What this means is, that most of the time you just work in your IDE
that has maven support (Eclipse or IDE do) and you let the IDE rebuild
your projects for you.
When you are ready to commit back into your SCM or you would like to
run the complete set of test (unit or integration) you break out to a
shell and run "mvn clean install" and check nothing is broken.
The incremental build cycle of an IDE will save you a lot more time
than trying to improve the Maven build process.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by Wayne Fay <wa...@gmail.com>.
> The problem with this is that I also need to build standalone jars of myLib2
> and myLib3, and they need myLib1 themselves. Their code refers to classes in
> myLib1 and myLib3 code defers also to classes in myLib2. myLib2 and myLib3 do
> not even compile if they don't have myLib1/myLib2 listed as dependency in
> their pom file. But if I list them as dependecies, those are expected to be
> found in a repository or manually installed. Otherwise if I list them as
> modules, I'm forced to packaging="pom", so no standalone jars...

Just set things up as you've been told and build your projects from
the top/parent each time, not from the children. Then the reactor
finds the files it needs when it builds each library. Use packaging of
"jar" in each lib, and use packaging "pom" for the top parent.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by Lucio Crusca <lu...@sulweb.org>.
In data lunedì 15 ottobre 2012 14:20:52, John Patrick ha scritto:
> If this was me I would create a new pom, which would be the parent for
> the 3 libraries, I would then also build at that level.
> 
> e.g.
> ~/mavenprojects/pom.xml (packaging pom)
> ~/mavenprojects/myLib1/pom.xml (packaging jar)
> ~/mavenprojects/myLib2/pom.xml (packaging jar)
> ~/mavenprojects/myLib3/pom.xml (packaging jar)
> 
> Basically that is how every project I've worked on works. You have to
> define the parent and relative Path correctly in the lib projects, and
> add modules into the parent pom.

The problem with this is that I also need to build standalone jars of myLib2 
and myLib3, and they need myLib1 themselves. Their code refers to classes in 
myLib1 and myLib3 code defers also to classes in myLib2. myLib2 and myLib3 do 
not even compile if they don't have myLib1/myLib2 listed as dependency in 
their pom file. But if I list them as dependecies, those are expected to be 
found in a repository or manually installed. Otherwise if I list them as 
modules, I'm forced to packaging="pom", so no standalone jars...


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: modules, dependencies, whatelse?

Posted by John Patrick <nh...@gmail.com>.
If this was me I would create a new pom, which would be the parent for
the 3 libraries, I would then also build at that level.

e.g.
~/mavenprojects/pom.xml (packaging pom)
~/mavenprojects/myLib1/pom.xml (packaging jar)
~/mavenprojects/myLib2/pom.xml (packaging jar)
~/mavenprojects/myLib3/pom.xml (packaging jar)

Basically that is how every project I've worked on works. You have to
define the parent and relative Path correctly in the lib projects, and
add modules into the parent pom. Basically one pom per thing,
sometimes over kill but often easier then scaling projects up or
moving between projects.

We have ~65 pom on my main project, ~15 are pom's to logically group
functionaility, some are simply a single wsdl or xsd, others are the
jpa layer.

Others might have different views but that is how I'd do it.

On 15 October 2012 12:51, Lucio Crusca <lu...@sulweb.org> wrote:
> Hello *,
>
> I'm new to maven. I'd like to mavenize three projects of mine. Let's say they
> are myLib1, myLib2 and myLib3. My directory structure is
>
> ~/mavenprojects/myLib1
> ~/mavenprojects/myLib2
> ~/mavenprojects/myLib3
>
> myLib3 depends on myLib1 and myLib2; myLib2 depends only on myLib1. The three
> libraries are in development stage, so I change their code very often. I need
> a maven setup that, when compiling myLib3, automatically compiles myLib1 and
> myLib2 also, if their source code has been changed, and recreates respective
> jars. The same goes for myLib2 in respect to its myLib1 dependency.
>
> I've tried adding myLib1 as a module of myLib2 in myLib2 pom file, but then I
> had to change the packaging to "pom", which stopped maven from compiling and
> packaging myLib2.
>
> Then I considered adding the compiled jars as dependencies, but in this case I
> don't have a maven repository to query, and I don't want to manually install
> myLib1 and myLib2 jars, since that would keep maven from recompiling the
> respective sources.
>
> What's the correct solution in my case?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org